Comments (7)
@guybedford I always thought this module would detect cjs exports at runtime.
what @BenSjoberg is saying is that anyone using star exports and updating to Typescript v4.4 will essentially have their module broken when running in node.js.
if typescript, babel, rollup, webpack, or any other compiler/bundler decide to change the syntax output just so slightly in the future without any runtime changes it'll break a bunch of users.
It was always clear this would happen to this package, and the policy was to treat this package as frozen because it is better to have things not be detected than be inconsistently detected. This is not a live package that will update to every transpiler change. The line has to be drawn and I know that's hard!
with that notion I think this module should have never been incorporated into node.js
and the cjs import should have just been left alone with requiring a default import.
from cjs-module-lexer.
This has been resolved thanks to microsoft/TypeScript#47070.
from cjs-module-lexer.
The problem is if this is fixed, as a user you will then be surprised when your package doesn't work on Node.js 14 / Node.js 12. Everything is fine then suddenly you get an issue from a user running your library in a Lambda.
For this reason we are weary to post feature changes to this package.
Note you can just do
import x from 'nestjs';
const { Export } = x;
And that will always work.
from cjs-module-lexer.
The problem is if this is fixed, as a user you will then be surprised when your package doesn't work on Node.js 14 / Node.js 12. Everything is fine then suddenly you get an issue from a user running your library in a Lambda.
Since those versions are still under LTS, would it be possible to backport the changes in this library to those versions of Node? (I guess that's a question for the Node.js team.)
I get that it might take some time for everyone to update, but it feels like the lesser of two evils to me. Due to the TypeScript change (assuming they don't implement a fix), every TypeScript-compiled CommonJS library is going to have its named exports done via export * from 'foo'
stop working from ESM over time, as maintainers upgrade to TS 4.4+. This is especially frustrating because I assume most package maintainers won't consider upgrading from TS 4.3 to 4.4 to be semver-major change for their package. (That's what brought my attention to this issue in the first place.) This could lead to scenarios where an ESM library stops working when an in-range update to one its CJS dependencies releases a new version compiled with TS 4.4+.
I completely understand your hesitancy though. Especially because there's no guarantee a future version of TS (or some other tool) won't change things again.
Note you can just do [...] And that will always work.
I know. I just wish that auto-imports would work that way when working with CJS modules in ESM code. It's frustrating to write imports that your editor (& the TypeScript compiler) thinks will work, that fail at runtime. Probably easier said than done though! (And obviously out-of-scope for this repo. 🙂)
from cjs-module-lexer.
It was always clear this would happen to this package, and the policy was to treat this package as frozen because it is better to have things not be detected than be inconsistently detected. This is not a live package that will update to every transpiler change. The line has to be drawn and I know that's hard!
from cjs-module-lexer.
The line has to be drawn and I know that's hard!
Fair enough. Thanks for your time anyway!
from cjs-module-lexer.
with that notion I think this module should have never been incorporated into node.js and the cjs import should have just been left alone with requiring a default import.
From my perspective, this module is only needed for old dependencies.
Maintained dependency (the ones that can update their typescript version, for example), can easily add an ESM entry point with the correct interface: by doing so they make sure that it can be imported regardless of the compiler they are using.
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
- 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.