Closed Aaronius closed 2 years ago
I assume you used webpack 4. Webpack 4 polyfills node builtins by default. Vite doesn't/won't polyfill node builtins for the browser but can be polyfilled with aliasses. you can use the package the ssr mode on the server
you are getting the warning because the library you are using haven't exported a browser friendly version. libraries should preferably not be using node builtins. if a library exports esm format it works best if all its dependencies also have esm export
vite is using index.module.js
as its specified for the module
export
the library could be more specific for environment target by using package entry points
docs about package entry points https://nodejs.org/api/packages.html#package-entry-points https://webpack.js.org/guides/package-exports/#providing-commonjs-and-esm-version-stateless
Thanks. I'll file an issue for @ensdomains/address-encoder.
Describe the bug
I don't know if this is a bug in Vite or the @ensdomains/address-encoder package. In our case, we're using bnc-onboard which has an indirect dependency on @ensdomains/address-encoder.
When bundling with Webpack, this worked fine. After migration to Vite, we receive:
It appears that the bundled code relies on node's crypto module. The workaround is to add this alias entry in our Vite config:
"@ensdomains/address-encoder": "@ensdomains/address-encoder/lib/index.umd.js"
So that the web-oriented bundle is used instead.
If you see this as an issue with @ensdomains/address-encoder, let me know and I can file an issue in that repo. Thank you!
Reproduction
I believe enough information is provided. Let me know if not.
System Info
Used Package Manager
npm
Logs
I'm just including the last part that may pertain to this issue.
Validations