8

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


Prashant Singh
  • 611
  • 1
  • 5
  • 14

3 Answers3

11

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'

Prashant Singh
  • 611
  • 1
  • 5
  • 14
4

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

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

instead of router from express package.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Ash Tah
  • 41
  • 3
0

Refering to the original error message, it's also possible to use a webpack plugin to automatically use polyfill when possible :

add package to your project by running :

npm install node-polyfill-webpack-plugin

add the plugin to webpack.config.js file :

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

then, in same file, add the plugin to you config :

plugins: [
  new NodePolyfillPlugin()
]

https://github.com/Richienb/node-polyfill-webpack-plugin

The plugin does what Prashant does plus many more others similar. It could be usefull on large project with a lot of unresolved dependency.

Nicoz
  • 71
  • 7