-
Notifications
You must be signed in to change notification settings - Fork 128
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 package entry points to avoid building of node builtins #323
Comments
same err |
I did some tests using the files in the lib folder: As the package.json has: "main": "lib/index.js",
"module": "lib/index.module.js", Vite ends up using what is set in the module field. If we delete the module field line, it uses the We could also set up: "main": "lib/index.js",
"module": "lib/index.module.js",
"types": "lib/index.d.ts",
"exports": {
"require": "./lib/index.js",
"import": "./lib/index.umd.js"
}, And it would use the import line. That "source": "src/index.ts",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"exports": {
"node": {
"require": "./lib/index.js",
"import": "./lib/index.module.js"
},
"browser": "./lib/index.umd.js"
}, This also works, and Vite/RollUp picks what is in the "browser" field. |
As a workaround for now, there are two options: resolve:{
alias:{
// ↓ see https://github.com/vitejs/vite/issues/6085
"@ensdomains/address-encoder": "@ensdomains/address-encoder/lib/index.umd.js",
},
} Or use a polyfill: resolve: {
alias: {
'crypto': 'crypto-browserify',
},
} |
When using a bundler like Vite (which does not polyfill node builtins) to build an app that has @ensdomains/address-encoder, compilation fails because @ensdomains/address-encoder depends on node's
crypto
module:This can fixed by using package entry points for address-encoder to be more specific about the target environments:
https://nodejs.org/api/packages.html#package-entry-points
https://webpack.js.org/guides/package-exports/#providing-commonjs-and-esm-version-stateless
More context can be found here:
vitejs/vite#6085
The text was updated successfully, but these errors were encountered: