normalize-url@1.9.1 dependency is not compatible with Webpack@5 out of the box
See original GitHub issue- Operating System: Ubuntu
- Node Version: 12.19.0
- NPM Version: 6.14.8
- webpack Version: 5.1.2
- mini-css-extract-plugin Version: 1.0.0
Actual Behavior
I am in the progress of upgrading my React toolset to Webpack@5. Running a compilation of some codebase I got the following error message
ModuleNotFoundError: Module not found: Error: Can't resolve 'url' in '/home/birdofprey/Documents/dr.pogodin.studio/react-utils/node_modules/normalize-url'
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: { "url": require.resolve("url/") }'
- install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "url": false }
I did not have a chance to dig deeper into it yet, and probably update the ticket with more info in the following days, but after a very brief look I found the following:
- Only two packages within dependencies depend on
normalize-url
: this one (on v1.9.1), andoptimize-css-assets-webpack-plugin
(on 3.3.0). - A note in
normalize-url
page mentions if you need to use this in browser, use version 4+, thus I guess the latestnormalize-url
should work with Webpack@5 out of the box, with no need of fallbacks. - I noticed this PR in past, which downgrated
normalize-url
: https://github.com/webpack-contrib/mini-css-extract-plugin/pull/399
Taking all these into account, I decided to already create this ticket, to check if somebody arounds knows more about it: is it still needed to keep old normalize-url
around? Is it possible to upgrade to its latest version, or drop/replace that dependency by something else?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
resolve.fallback: { "url": false } - You.com - You.com
This is what I'll be using for now until I can find a better solution. Open side panel. Module not found: Error: Can't...
Read more >Upgrade to Webpack 5 failing - node.js - Stack Overflow
You need to fix scripts/start.js file. There is a line in this file: const compiler = createCompiler(webpack, config, appName, urls, ...
Read more >Npm package installation error on other partition
I'm getting this error whenever I install a package from npm on another partition: npm ERR! code 126 npm ERR! path ...
Read more >Relay
The Relay compiler will then ensure that the data dependencies declared in such fragments are fetched as part of that parent query. import...
Read more >Web Libraries in Jars - WebJars
angular-translate-loader-url, org.webjars, angular-translate-loader-url ... org.webjars.bower, bootstrap-star-rating-fork-boostrap-dependency, 3.5.4.
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 Free
Top 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
@evilebottnawi Huge thanks for the remark about migration to css-minimizer!
Regarding this ticket, the problem is that to use this (
mini-css-extract-plugin
) with Webpack@5, at least in some corner-cases one needs to addresolve.fallback.url: require.resolve('url')
to his Webpack config, and installurl
package as the dependency. It solves the issue for me, but this looks like an avoidable inconvenience, caused by you depending on legacy version ofnormalize-url
.Do not use
optimize-css-assets-webpack-plugin
migrate to https://github.com/webpack-contrib/css-minimizer-webpack-plugin