找不到模块:错误:无法解析 webpack 5/Angular 14 中的“url”

Pra*_*ngh 9 angular angular14

在运行安装在 Angular 14 中的 [deepstream.io-client-js][1] 项目时,出现以下错误。[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 }```


Run Code Online (Sandbox Code Playgroud)

Pra*_*ngh 14

正如我们在错误中看到的,添加 polyfill 有 2 个步骤,首先在tsconfig.json级别创建一个webpack.config.js文件并添加如下代码。

步骤 1.webpack.config.js

module.exports = {
  resolve: {
    fallback: { "url": require.resolve("url/") }
  }
};
Run Code Online (Sandbox Code Playgroud)

步骤 2. 运行 npm i url for - install 'url'