Use `exports` field with `.mjs` extension instead of `"module": "dist/polished.esm.js"` in `package.json`
tkamenoko opened this issue · 0 comments
tkamenoko commented
Summary
polished
provides an esm export via module
field in package.json
. However, Node.js does not support module
field. Using exports
field and .mjs
extension is recommended to provide cjs/esm dual package.
https://nodejs.org/api/packages.html#packagejson-and-file-extensions
Node.js uses type
field and each file extension to decide file type. module
field has no effect.
Example
This example shows what files are actually imported when importing packages. prettier
has both cjs
and mjs
exports, and its main
field value is "./index.cjs"
.
// import-test.mjs
console.log(import.meta.resolve("polished"));
console.log(import.meta.resolve("prettier"));
node --experimental-import-meta-resolve ./import-test.mjs
Result:
file://path/to/workspace/node_modules/polished/dist/polished.cjs.js
file://path/to/workspace/node_modules/prettier/index.mjs
cjs
is selected for polished
while mjs
is selected for prettier
.