-
Notifications
You must be signed in to change notification settings - Fork 293
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
Support for ECMAScript Modules (ESM) #236
Comments
Node doesn't honor the |
Yea, agree. That's why through flag will be the best way. It won't break anything, but will allow above scenarios. And generally, it doesn't make sense to create a whole new tool just because few bytes change and some resolving thingy :) |
FYI there are currently no proposals to support the |
Agree. But still. Good tools should have flexibility. Such option won't break anything for I'm asking at least for a flag/option, which won't hurt anyone :) |
Our zeit now builds started failing last week due to ncc hitting the editions autoloader for various packages, which their The editions autoloader is skipped by browserify etc, as they prefer the I've been looking into options here for what I can do to rectify this, as Bevry's libraries/utilities are quite popular, with the editions autoloader getting millions of downloads a month. Having ncc support the Other than that, does ncc prefer Otherwise, I may need to look into making the editions autoloader a node.js require extension for package.json files, which would be a major usability hurdle. The ideal of course would be if bundlers added first class support for the editions format, that way, ncc, as it supports typescript, could elect for the source edition for typescript projects. |
@balupton perhaps there is a way you could design the autoloader to be ncc-compatible? For example using non-analyzable requires to ensure it builds the right way between ncc and Node native? I know its not pretty, but something like: if (ncc) {
require('./main.js');
}
else {
eval(fs.readFileSync('./autoloader.js'))
} sort of thing. Unfortunately supporting the For an |
Correct, where the Seems for me, the cleanest option would be if ncc at a minimum supported the module field. I think that the module field is desirable for ncc, as to my knowledge, ESM provides better tree shaking abilities than CJS. Would be even better if ncc supported the editions format, that way they could include the typescript source if available, rather than compiled code. Just by trickling through the editions until they find the one they support. |
The There will be a new |
Seems As such, The advantage of |
.mjs is supported, yes, but only when explicitly used in the main field - The ability for the default extension for a |
So their goal does not include backwards compatibility? Regardless of the working group. I think it is important that packages that work today also work with bundlers. So far the only solution provided is an eval trick, that increases burden on package authors and increases complexity with other bundlers. If ncc added the module field, like many bundlers now do, or added mjs support, then life would be easier, without concern for the working group's complications. At this point, my builds are failing and any package that uses editions will fail with zeit's now and ncc. This leaves the options as:
Other bundlers don't have this issue, as they use the browser field, which the hundreds of editioned packages already provide. |
And the node.js ecosystem without custom bundlers, correct? |
Just to throw little comment here again :) When I did a fork with this small change and used it for couple of packages it worked perfectly, even successfully bundled eslint and such. |
I guess we could support a "module": true option, although I really wouldn't recommend it, especially with pika using that now to mean "browser + module", where ncc would want "node + module". But I don't think @bevry is asking for the "module" field either though. |
Good point. Really makes me think that https://editions.bevry.me approach of each edition having tags that can be used for language and module system, as well as an engines field, is the right away to go about this. How hard would it be to add editions support to ncc? Could it be done as a plugin install and a one line configuration option? If pointed in the right direction, I could find time to do it myself, or place a bounty/commission for its development. Also thank you for the dialogue. Keen to get a working approach happening. |
module
-first resolving, instead of forcing main
-first
Any progress on this? It really worths nothing to set |
That's it. tunnckoCore@2d83d3a ( I'll maintain the fork for now. And one another strange thing: why there is no ESLint or Prettier setup here? Additionally in my fork added prettier. |
Fixed in #720 by detecting |
Continuation of few comments on #21.
Even that this is Node oriented, it still should understand
module
field. That's not against the intent of the project, the output is still node compatible because it is CJS. The module-first is only helping for smaller outputs of thencc
-ed package, because webpack does better tree shaking over ES Modules.I tried. And it's definitely a thing. Consider the following.
Package
foo
and packagebar
. Both are written in ESM. Both havemodule
field. Wencc
thebar
package (with--minify
), which uses only a few things from thefoo
package. The output of thebar
package, won't have the unused things from thefoo
package. Iffoo
does not have themodule
field, thebar
output includes everything fromfoo
.If not by default, at least support a flag option for this.
Reproduce: https://github.com/tunnckoCore/ncc-modules
Open the
packages/bar/dist/index.js
and you won't see the FOO_PKG because it isn't used inbar
.The only local change on node_modules on
ncc
is just removing themainFields
option. And still, the outputs are node compatible and CJS, so I don't see why not support this thing, by default with the Webpack's default resolving['module', 'main']
. Also, even if everything is written in CJS or package does not havemodule
field Webpack will fallback tomain
anyway.The text was updated successfully, but these errors were encountered: