繁体   English   中英

Webpack < 5 使用 firebase 管理员时出现问题

[英]Webpack < 5 Issue when using firebase admin

当我想使用以下代码使用 firebase admin SDK 时

import * as admin from 'firebase-admin';
var serviceAccount = require("../services/serviceAccountKey.json");
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://voter-60a9f-default-rtdb.europe-west1.firebasedatabase.app"
});

我收到这个错误

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

这只是其中之一。 我也有这个:

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 }

等等....

我尝试重新安装 Node 模块,但没有成功。 我也不明白我应该在哪里添加他们建议的回退。 如果我能找到它,我是否需要为所有节点模块添加它?

谢谢!

我遇到了同样的错误你可以做的是 go 到 node_modules/react-scripts/config/webpack-config.js 并进行这些更改

resolve: {
  modules: ...,
  extensions: ...,
  alias: {...}, fallback: {
    "fs": false,
    "tls": false,
    "net": false,
    "path": false,
    "zlib": false,
    "http": false,
    "https": false,
    "stream": false,
    "crypto": false,
    "crypto-browserify": false,
    "url": require.resolve("url"),
    "os": false,
    "os-browserify": false,
    "querystring": false,
    "buffer": false,
    "constants": false,
    "child_process": false
  },
  plugins: [...]
},

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM