Comments (9)
/cc @lukastaegert
from cjs-module-lexer.
Previously, these packages "just worked" for named imports from Node.js in ESM mode because cjs-module-lexer was able to detect the re-exports
Note that it's probably too late to make it work again in Node.js 12 so probably many users will be stuck with getting "named" import from the default import.
from cjs-module-lexer.
PR that introduced the change in rollup: rollup/rollup#3959
from cjs-module-lexer.
cc @guybedford
from cjs-module-lexer.
Seems weird to me why this change would break the lexer, but I am no expert on this matter. For Rollup, it fixes a serious bug and improves spec compliance.
from cjs-module-lexer.
@lukastaegert It's because the new Rollup output has changed, and it doesn't match anymore the patterns recognized by this package (specifically, EXPORT_STAR_LIB
in https://github.com/guybedford/cjs-module-lexer#grammar).
Fwiw, as a Babel maintainer I will never consider the generated output that cjs-module-lexer
relies on part of the public API and thus I'll break it when needed even in patch releases. I love that Node.js uses this package to make it easier to import cjs dependencies, but:
- It's meant to be used when importing a old cjs packages: since they are "old" they won't unpdate their Rollup/Babel dependencies, because a new release would make them "new"
- New packages shouldn't rely on this Node.js cjs interop since it's inherently unstable, but they should provide a proper ESM entrypoint with curated exports.
I'll still try to notify @guybedford (or even open a PR) whenever Babel's exports output changes.
from cjs-module-lexer.
It is an unfortunate combination and I too feel that tools should not have to cater to what cjs-module-lexer
is able to detect when performing code generation. However the reality here is due to its use in Node.js this can cause unintended breakage for existing packages by simply upgrading the build tools (in this case Rollup, Babel or TS).
There are several aspects at play here:
-
As package authors, I can introduce a dedicated Node esm build, however that requires introducing the
exports
field if previously not present, and can potentially be a breaking change; -
As tooling authors: it would be ideal not to have to care about
cjs-module-lexer
for code generation.
I understand why Node provides named imports interop for cjs modules, but it feels a bit flaky for it to be based on code-generation-pattern specific static analysis (which leads to this problem here).
from cjs-module-lexer.
I've put together a PR in #41. There have been a few changes coming together here, so when the release is made I can work on getting this backported as far as possible on the Node.js release lines. Support on Node.js 12 may not be possible though unfortunately.
This project is very much a bandaid and a hack, bridging a divide that was never quite bridgeable. Hopefully we can avoid too much churn during this transition period.
@lukastaegert I've also added detection for Object.hasOwnProperty
check in the same sort of way. If you can think of any other patterns you want to future proof now please put some thought to it - happy to add further changes into this.
The Node.js release cutoffs will start to become a problem with this project where we risk things working in modern Node.js then failing in older versions. For that reason we should try to avoid changes to this project as much as possible, or where needed to make them sooner rather than later while the backports are still possible.
from cjs-module-lexer.
Hi @guybedford, please reopen this issue, because it's not fixed due to the typo here: https://github.com/guybedford/cjs-module-lexer/pull/41/files#r667619960
from cjs-module-lexer.
Related Issues (20)
- Extending exports object detections HOT 20
- add tag for 1.2.2 HOT 4
- node ES6 import throws this error. HOT 18
- Error selecting connection connect ECONNREFUSED 127.0.0.1:5432
- Function call changes in TypeScript 4.4 seem to be breaking detection of named exports HOT 7
- Can't export when enumerable is "!0"
- When trying to build with snowpack this error is thrown HOT 4
- Not work well with TypeScript export default as output HOT 2
- exports can be detected in hashbang
- Feature Request: Also detect esbuild Re-exports HOT 1
- Bug: cannot detect exported numbers HOT 5
- Incompatibility with TypeScript (edge case) HOT 3
- Issue with parsing 'react-transition-group' HOT 2
- Rollup ^3.0.0 cjs re-exports edge case with externalLiveBindings: false HOT 8
- Out of bounds memory access HOT 1
- Real world edge case: prettier HOT 1
- Add RISC-V Support HOT 2
- Unable to detect exports from bundled webpack output HOT 6
- Cannot load externalized builtin: "internal/deps/cjs-module-lexer/lexer:/usr/lib/node_modules/cjs-module-lexer/lexer.js". HOT 9
- Allow externalized Wasm build HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cjs-module-lexer.