-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Imply ES6 module package, when package.json contanis 'module':... #34027
Comments
This is for the cases lacking "exports" in |
I've actually searched quite a bit about node and the package.json |
Please don't adopt this proposal, as it would instantly break Underscore and probably many other packages as well. The module field was intended as a way for packages to publish their ESM entry point to environments that support it while still using If anything, the presence of both a |
How shall the presence of |
No different from any other package with the absence of Better would be if Node.js could interpret the In my ideal world, there wouldn't be such a rigid, restrictive segregation between ESM and CommonJS in the first place. For a package maintainer like myself, who is trying to cater to many environments and module systems at the same time, it is currently much easier to avoid the experimental ESM support in Node.js entirely and refer people to third-party tools like Rollup and esm instead. See jashkenas/underscore#2874 for some context. |
Take as example: /~https://github.com/rollup/plugins/blob/master/packages/babel/package.json . It has 'module' and 'main' fields, but not 'type' field. When I use the plugin over a rollup-configuration file, then rollup might load dist/index.es.js . When I write javascript file, that imports This leads to a situation, where a package is read as ES6 module, when the package is a rollup plugin, loaded over a rollup configuration file, and the same package is used as commonjs, when rollup is initialized with direct javascript. In fact, the main, module and type fields present four states:
Why is the last case necessary? |
@dilyanpalauzov I'm failing to see the difference between case 2 and 4, other than which side of the equation you consider to be the "official" one. And that's exactly my gripe with the segregation in Node.js: why should one module system necessarily be "more important" than the other? Rollup takes a much friendlier approach in my opinion: every package that follows its The problem you're describing boils down to Rollup and Node.js having different, incompatible conventions. To have them play nice together, at least one of them would have to adopt the convention of the other. Since we're discussing Node.js in here, that means it would have to adopt the notion that if you're doing an ESM package import and the target package has a Until the situation has improved, I simply suggest not mixing the systems. Rollup plugins are meant to run in Rollup context, which provides ESM support, so there is no need to involve the experimental ESM support from Node.js as well. If you want to use ESM code that was written for Rollup in a non-Rollup context, use a deep import path with the esm loader. |
I'm not keen on supporting this proposal, use "type": "module" or ".mjs" files. Determining formats is already complex, and "module" isn't the only field in the wild that would hold this same kind of oddity. Additionally that only defines some hint about the nature of the entry point, not any subpaths such as CC: @nodejs/modules-active-members |
This was discussed in great depth when the current ES module support was designed. The short answer is that Node can’t support This was discussed in the ES modules implementation announcement blog post: /~https://github.com/nodejs/modules/blob/master/doc/new-implementation-announcement.md#es-module-code-in-packages |
In my package.json I have
'type':'module'
and in my code I writeimport babel from '@rollup/plugin-babel
. The package.json of the latter contains"main": "dist/index.js", "module": "dist/index.es.js"
but there is no'type':'module'
. In turn nodejs concludes that@rollup/plugin-babel
is commonjs and there is no way to use the default import fromdist/index.es.js
. This means I have to writebabel.default
in my code and I cannot useimport {babel} from '@rollup/plugin-html
.• When NodeJS imports a package(.json) that contains 'main' and 'module' fields, but no 'type' field, from a package containing
'type':'module'
, implicitly conclude that the imported package is an ES6 module.The text was updated successfully, but these errors were encountered: