Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Error: Can't resolve 'url' in webpack 5/Angular 14

While running a project with deepstream.io-client-js installed in angular 14, getting following error.

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 }
like image 932
Prashant Singh Avatar asked Mar 25 '26 20:03

Prashant Singh


2 Answers

As we can see in error there are 2 steps to add polyfill, first create a webpack.config.js file at tsconfig.json level and add the code as below.

Step 1. webpack.config.js

module.exports = {
  resolve: {
    fallback: { "url": require.resolve("url/") }
  }
};

step 2. run npm i url for - install 'url'

like image 56
Prashant Singh Avatar answered Mar 27 '26 12:03

Prashant Singh


Have a look at your import statements. Make sure you are using:

import { Router } from '@angular/router'; 

instead of router from express package.

like image 35
Ash Tah Avatar answered Mar 27 '26 11:03

Ash Tah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!