Skip to content

Conversation

dynst
Copy link

@dynst dynst commented Aug 13, 2025

"module" is a non-standard field that Node.js doesn't read. It uses "exports".

ESM code also needs the .mjs file extension.

https://nodejs.org/api/packages.html#determining-module-system

dynst added 2 commits August 13, 2025 20:19
ESM projects can now import the tree-shakeable ESM code. Node.js doesn't use the "module" field.
@Daninet
Copy link
Owner

Daninet commented Aug 13, 2025

Do you know if this syntax is supported by FE tooling like Webpack 4/5, Rollup, esbuild, parcel etc?

@dynst
Copy link
Author

dynst commented Aug 13, 2025

It's from Node v12 https://nodejs.org/en/blog/release/v12.7.0 so almost everything should support it by now.

Webpack 5 added support in 2020. https://webpack.js.org/blog/2020-10-10-webpack-5-release/ so version 4 didn't have it.

Rollup definitely has it. rollup/plugins#208 (comment) Since at least node-resolve v11. rollup/plugins#540

dynst added 2 commits August 13, 2025 23:44
This field is ignored by all modern tools when "exports" is present.
now they live next to the files they describe, thanks to rootDir. tsconfig.json seems to be completely ignored and unused here.
@dynst dynst force-pushed the esm-exports branch 3 times, most recently from c0953c1 to 824f871 Compare August 14, 2025 05:07
index.ts -> index.mjs, argon2.ts -> argon2.mjs, rather than bundled into one giant file.
es2017 is a superset of es7, which is a superset of es6. So use es2017 consistently for target and lib.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants