Search code examples
angularangular14

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


While running a project with [deepstream.io-client-js][1] installed in angular 14, getting following error. [1]: https://www.npmjs.com/package/deepstream.io-client-js

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 }```



Solution

  • 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'