-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider unstable flag to make cjs files be treated as esm #22818
Comments
There are already so much "unstable" flags available, that I would try to avoid another one, whenever possible. But it would be very appreciable, if we could have a central detection mechanism -- including something similar to nodejs/node#50096 resp. its Right now That's why I'm fighting in #22840 some Please could you take a scrutinizing look at my draft PR (#22841) to solve this issue in this other place as well. Nevertheless, a more general solution for the file type detection and more reliable unit tests for its proper application would indeed make a lot of sense in the long run. |
I would also prefer this to be handled automatically, same as Bun does, and for sure Node would also do this as soon they stabilize their experimental flag described here. |
Once Node does that then we'll also change the behaviour to align with Node, but doing non-standard Node behaviour for Node compat makes the ESM/CJS situation in the Node ecosystem worse and not better (encourages people shipping and writing code that doesn't work with Node's resolution). I understand it's convenient for apps to have this behaviour though, which is why this non-standard Node behaviour will most likely be behind a flag. |
In this particular case we just have to figure out, which kind of import format should be used for a particular file. This can be simply decided by 1. the suffix, 2. enclosing We just have to figure out one question: how to handle the given files in the most appropriate manner? If none of this criteria fits, we can still fall back to some very old fashioned defaults... A perfect emulation of all the faults, inflexibility and historic burden of |
Upon further reflection, what I said in my previous comment isn't as relevant to Deno because Deno already treats everything outside node_modules as an ES module, so someone could already develop an npm package without properly setting up their package.json for distribution for Node. I opened #22945 that implements this behaviour without a flag. |
I'm in the processing of writing a more extensive answer about this topic in #17650. We have very likely slightly different opinions on this topic, but I really like the way how you tireless advocate for improvement and practical change! :) |
Changes the behaviour in Deno to just always load ES modules in npm packages even if they're defined as CJS. Closes #22818
It would be useful to have an unstable flag that allows people to import CJS files that contain imports/exports similar to Node's
--experimental-detect-module
.For example: #22811
The text was updated successfully, but these errors were encountered: