firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.6k stars 358 forks source link

Firebase: Module not found: Can't resolve 'fs' needed an alteration #2041

Open xcollantes opened 1 year ago

xcollantes commented 1 year ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

  1. Download Firebase admin: npm install firebase-admin
  2. Start locally: npm run dev

I get an error:

error - ./node_modules/@google-cloud/storage/build/src/bucket.js:21:0 Module not found: Can't resolve 'fs' 

I am able to resolve this issue by adding this snippet to my next.config.js file:

/** @type {import('next').NextConfig} */
const nextConfig = {
  future: {
    webpack5: true, // by default, if you customize webpack config, they switch back to version 4.
    // Looks like backward compatibility approach.
  },
  webpack(config) {
    config.resolve.fallback = {
      ...config.resolve.fallback, // if you miss it, all the other options in fallback, specified
      // by next.js will be dropped. Doesn't make much sense, but how it is
      fs: false, // the solution
    }

    return config
  },
}

module.exports = nextConfig

The error was resolved BUT I would expect this dependency to work without having to alter my configuration in NextJS since this is a common framework. Is there a way to fix this to not have to alter my configuration?

fec57f57-44e2-44dd-832b-ac37a20c5739

google-oss-bot commented 1 year ago

I found a few problems with this issue:

lahirumaramba commented 1 year ago

Hi @xcollantes Firebase Admin SDKs are server libraries that should be used in privileged server environments. The Admin Node.js requires full Node.js runtime to work properly. Can you explain your use-case here? Are you trying to build your server app (that uses firebase-admin) with webpack?