Angular 18 google-auth-library 错误(Webpack)

问题描述 投票:0回答:1

当我的 Angular 应用程序运行无服务时,我遇到了一系列错误,该应用程序是安装 google-auth-library 后的最新版本。错误是 -

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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

有很多这样的,还有‘fs’、‘http2’、‘zlib’。

显然解决方案是在 config.webpack.js 中添加 polyfill,但这在 Angular 中不存在。

有人解决这个问题了吗?

谢谢

angular webpack
1个回答
0
投票

由于@sjsam的回答,我能够解决这个问题

https://stackoverflow.com/a/69212673/1122187

我做了以下事情-

tsconfig.js

 "compilerOptions": {
    "paths": {
      "stream": ["./node_modules/stream-browserify"],
      "util": ["./node_modules/util"],
      "url": ["./node_modules/url"],
      "assert": ["./node_modules/assert"],
      "crypto": ["./node_modules/crypto-js"],
      "http": ["./node_modules/stream-http"],
      "https": ["./node_modules/https-browserify"]
    },
...

角度.json

"architect": {
        "build": {
          "options": {
            "allowedCommonJsDependencies": [
              "stream",
              "util",
              "url",
              "assert",
              "crypto",
              "http",
              "https"
            ],
...

  

最后安装所有出现错误的插件

npm i stream-browserify --force
...

然后重新启动构建。每个 webpack 错误都应该得到解决。

© www.soinside.com 2019 - 2024. All rights reserved.