admin管理员组文章数量:1134248
I've seen some npm packages (vue for example) have a module
field in their package.json.
But module
is not included in the package.json documentation - is this a convention of some kind? Is there documentation for this somewhere?
I've seen some npm packages (vue for example) have a module
field in their package.json.
But module
is not included in the package.json documentation - is this a convention of some kind? Is there documentation for this somewhere?
- 2 convention for ECMAScript modules - here's a good read on the different approaches to identifying ESM's: hackernoon.com/… – hackerrdave Commented Mar 10, 2017 at 1:38
2 Answers
Reset to default 213Update: April 2022
The module
field is not officially defined by Node.js and support is not planned. Instead, the Node.js community settled on package exports which they believe is more versatile.
For practical reasons JavaScript bundlers will continue to support the module
field. The esbuild docs explain when to use module
as well as related fields main
and browser
.
Original Answer
Is
"module"
an official npm property or is this a convention of some kind?
It's a proposal, but likely to be supported due to de facto usage.
Is there documentation for this somewhere?
There is, in fact, and it can be found right here and later removed here.
What's it for?
ES6 Module Interoperability in Node. Additional discussion can be found here and here. And here's a blog post from Rich Harris talking more about it.
This is used by bundler tools for ESM (ECMAScript Module) detection. The Rollup documentation says it pretty well:
If your
package.json
file also has amodule
field, ES6-aware tools like Rollup and webpack 2 will import the ES6 module version directly.
This article on Rollup 1.0 says it another way:
The
main
field makes sure that Node users usingrequire
will be served the UMD version. Themodule
field is not an official npm feature but a common convention among bundlers to designate how to import an ESM version of our library.
Further discussion of pkg.module
is on the Rollup Github Wiki and the webpack Docs.
本文标签: javascriptWhat is the quotmodulequot packagejson field forStack Overflow
版权声明:本文标题:javascript - What is the "module" package.json field for? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736831166a1954701.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论