Webpack v5 support
See original GitHub issuePolyfils aren’t no longer injected for the latest version of webpack. GatsbyJS is already using webpack v5. I’d also like to upgrade my own umd package which uses WC.
Example error message during webpack build:
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "util": false }`
Issue 1: Gotta have those polyfils
Rather than force every app to manually add these packages, they should already be included in the WC packages.
Issue 2: Using Node.JS modules in a browser application
Is this a concern? I read that its not recommended but haven’t researched enough to know for sure. Similar issue in another package: https://github.com/angular/angular-cli/issues/20819#issuecomment-842307462
Temporary Solution
In your application that uses Webpack V5, make the following changes
yarn add stream-browserify stream-http crypto-browserify https-browserify os-browserify util url assert
Then update your webpack config. Here’s a GatsbyJS example:
// gatsby-node.js
exports.onCreateWebpackConfig = ({ stage, actions }) => {
actions.setWebpackConfig({
resolve: {
fallback: {
util: require.resolve(`util/`),
url: require.resolve(`url/`),
assert: require.resolve(`assert/`),
crypto: require.resolve(`crypto-browserify`),
os: require.resolve(`os-browserify/browser`),
https: require.resolve(`https-browserify`),
http: require.resolve(`stream-http`),
stream: require.resolve(`stream-browserify`),
},
},
})
}
See stack overflow for more info
Issue Analytics
- State:
- Created 2 years ago
- Comments:17
Top Results From Across the Web
To v5 from v4 - webpack
To v5 from v4. This guide aims to help you migrating to webpack 5 when using webpack directly. ... Now let's upgrade webpack...
Read more >Top 5 Changes in webpack v5 - Ryan H. Lewis
Webpack v5 requires a minimum of Node.js v10 to run. Node.js v10 just left LTS support in June 2021, so you should really...
Read more >Webpack 5 Issues | Documentation - Web3Auth
js packages have certain dependencies, which are not present within the browser environment by webpack 5. Hence, you require certain node polyfills to...
Read more >Webpack 5 Adoption - Next.js
Improved Long Term Caching of Assets: Deterministic code output that is less likely to change between builds; Improved Tree Shaking; Support for assets...
Read more >How to polyfill node core modules in webpack 5 - Alchemy
This config-overrides.js code snippet is telling webpack how to resolve the missing dependencies that are needed to support web3 libraries and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I did it differently. I’ve modified my package.json the following way, and it compiled:
I don’t think we should depend from Node.js stuff in our browser dapp.
P.S.: after recompiling it broke again with
Uncaught TypeError: util.inherits is not a function
. I’ve fixed it with:P.P.S.: after compiling again it broke once again with something related to url.parse. I’ve fixed with:
It’s ridicolous that we have to deal with all this.
For
CRA v5
, this can be fixed with CRACO or react-app-rewired. In case of CRACO, the.cracorc.js
should look likeAnd the following packages must be included in the
packages.json
: