Skip to content
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

Use exports field with .mjs extension instead of "module": "dist/polished.esm.js" in package.json #649

Open
tkamenoko opened this issue Feb 24, 2024 · 0 comments · May be fixed by #650
Open

Comments

@tkamenoko
Copy link

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 .

tkamenoko added a commit to tkamenoko/polished that referenced this issue Mar 21, 2024
…standard

To meet Node.js standard, 2 things should be fixed:

* ESM file should use `.mjs` extention
instead of `.esm.js`.
* `module` field in `package.json` is not standard way of Node.js. Use
`exports` field instead.

fix styled-components#649
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant