简体   繁体   中英

Webpack < 5 Issue when using firebase admin

When i want to use the firebase admin SDK using the following code

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"
});

I get this error

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 }

This is just one of many. I also have this:

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 }

and so on....

I tried reinstalling the Node modules but no luck. I also dont understand where i should add that fallback they suggest. And if i would find it, do i need to add this for all the node modules?

Thanks!

I faced this same error what u can do is go to node_modules/react-scripts/config/webpack-config.js and make these changes

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: [...]
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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