Open
Conversation
ESM projects can now import the tree-shakeable ESM code. Node.js doesn't use the "module" field.
Owner
|
Do you know if this syntax is supported by FE tooling like Webpack 4/5, Rollup, esbuild, parcel etc? |
Author
|
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 |
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.
c0953c1 to
824f871
Compare
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.
|
I haven't tested the above, but I can confirm that the current package cannot be implemented as a module by tools like tsdown. As a workaround, I've had to vendor the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
"module"is a non-standard field that Node.js doesn't read. It uses"exports".ESM code also needs the
.mjsfile extension.https://nodejs.org/api/packages.html#determining-module-system