Giter Club home page Giter Club logo

Comments (7)

dnalborczyk avatar dnalborczyk commented on July 4, 2024 2

@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.

guybedford avatar guybedford commented on July 4, 2024 1

This has been resolved thanks to microsoft/TypeScript#47070.

from cjs-module-lexer.

guybedford avatar guybedford commented on July 4, 2024

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.

BenSjoberg avatar BenSjoberg commented on July 4, 2024

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.

guybedford avatar guybedford commented on July 4, 2024

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.

BenSjoberg avatar BenSjoberg commented on July 4, 2024

The line has to be drawn and I know that's hard!

Fair enough. Thanks for your time anyway!

from cjs-module-lexer.

nicolo-ribaudo avatar nicolo-ribaudo commented on July 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.