firebase-admin-node: firebase-admin dependency errors

  • Operating System version: macOS 10.12.6
  • Firebase SDK version: 5.2.1
  • Library version: 5.2.1
  • Firebase Product: admin

I’m seeing some dependency issues. firebase-admin: 5.2.1

➜  customer-manager (master) ✗ yarn add firebase-admin                                                    .../customer-manager
yarn add v0.27.5
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 2 new dependencies.
├─ @google-cloud/storage@1.2.1
└─ firebase-admin@5.2.1
Done in 4.74s.

➜  customer-manager (master) ✗ yarn start                                                                 .../customer-manager

yarn start v0.27.5
$ node build/dev-server.js
> Starting dev server...

 ERROR  Failed to compile with 22 errors                                                                            10:37:27 PM

These dependencies were not found:

* fs in ./~/firebase-admin/lib/auth/credential.js, ./~/@google-cloud/storage/src/bucket.js and 10 others
* net in ./~/faye-websocket/lib/faye/websocket/client.js, ./~/forever-agent/index.js and 3 others
* tls in ./~/faye-websocket/lib/faye/websocket/client.js, ./~/forever-agent/index.js and 1 other
* child_process in ./~/google-auth-library/lib/auth/googleauth.js
* dns in ./~/isemail/lib/isemail.js

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 37 (5 by maintainers)

Most upvoted comments

There’s no resolution. If your runtime complains about missing dependencies like fs, net and child_process, then that’s a good indication that the Admin SDK should not be used in that environment.

Are you trying to use firebase-admin in a client-side or browser environment? That is not supported. Some of the missing modules (fs, net etc.) are only available in server-side Node.js environments.

I found that I received this error in Next.js when I mingled my firebase-admin app with my firebase client side app. To solve it, I ensured that firebase-admin was never imported in a client-facing file, and then (and this is crucial) I separated the initialisation of the two apps so they were initialised in separate files.

@crossRT did you found any solutions? I try to use firebase-admin with Netlify functions and get similar errors.

You áre using the same library at front-end and it is nota possible.

Firebase is used at front-end Firebase-admin is used at back-end

I installed firebase-admin at back-end and it worked.

“react”: “^16.13.1” “firebase”: “^7.19.1” “firebase-admin”: “^9.1.1”

./node_modules/hash-stream-validation/index.js Module not found: Can’t resolve ‘fast-crc32c’

./node_modules/configstore/node_modules/write-file-atomic/index.js Module not found: Can’t resolve ‘worker_threads’

Facing this Issue while trying to add Firebase Admin SDK to my React Web app

I installed firebase-admin on a brand new project which running webpack4 + typescript, getting these dependencies issue as well.

WARNING in ./node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js
16:20-67 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js
 @ ./node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js
 @ ./node_modules/grpc/src/grpc_extension.js
 @ ./node_modules/grpc/index.js
 @ ./node_modules/@google-cloud/common-grpc/src/index.js
 @ ./node_modules/@google-cloud/firestore/src/index.js
 @ ./src/index.ts

WARNING in ./node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js
19:22-48 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js
 @ ./node_modules/grpc/src/grpc_extension.js
 @ ./node_modules/grpc/index.js
 @ ./node_modules/@google-cloud/common-grpc/src/index.js
 @ ./node_modules/@google-cloud/firestore/src/index.js
 @ ./src/index.ts

WARNING in ./node_modules/grpc/src/grpc_extension.js
32:12-33 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/grpc/src/grpc_extension.js
 @ ./node_modules/grpc/index.js
 @ ./node_modules/@google-cloud/common-grpc/src/index.js
 @ ./node_modules/@google-cloud/firestore/src/index.js
 @ ./src/index.ts

WARNING in ./node_modules/bytebuffer/dist/bytebuffer-node.js
Module not found: Error: Can't resolve 'memcpy' in '/Users/crossrt/www/malaysia-election/node_modules/bytebuffer/dist'
 @ ./node_modules/bytebuffer/dist/bytebuffer-node.js 29:38-55
 @ ./node_modules/protobufjs/dist/protobuf.js
 @ ./node_modules/grpc/index.js
 @ ./node_modules/@google-cloud/common-grpc/src/index.js
 @ ./node_modules/@google-cloud/firestore/src/index.js
 @ ./src/index.ts

Any idea how could these happened?

Thanks for your help, it didn’t work. It shows:

Module not found: Error: Can’t resolve ‘fast-crc32c’ in ‘C:\Users\xxxxxxx\Desktop\Development\nuxt\project4\node_modules\hash-stream-validation’

ERROR Failed to compile with 43 errors 12:22:22 These dependencies were not found:

  • child_process in ./node_modules/google-auth-library/build/src/auth/googleauth.js, ./node_modules/grpc/node_modules/detect-libc/lib/detect-libc.js
  • fs in ./node_modules/@google-cloud/storage/src/file.js, ./node_modules/@google-cloud/storage/src/bucket.js and 34 others
  • net in ./node_modules/forever-agent/index.js, ./node_modules/tough-cookie/lib/cookie.js and 1 other
  • tls in ./node_modules/forever-agent/index.js, ./node_modules/tunnel-agent/index.js To install them, you can run: npm install --save child_process fs net tls

I tried this settings and it worked so far.

{
    "next": "11.0.1",
    "firebase": "^8.6.8",
    "firebase-admin": "^9.10.0"
}
// next.config.js
module.exports = {
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.resolve.fallback.fs = false
      config.resolve.fallback.child_process = false
      config.resolve.fallback.request = false
      config.resolve.fallback.net = false
      config.resolve.fallback.worker_threads = false
      config.resolve.fallback.tls = false
    }
    return config
  }
}

@hiranya911 @aaaguirrep This is not an issue with running in a browser. For me this is using TypeScript/Node deploying to backend AWS Lambdas. This is the same thing Netlify is doing.

To be clear, I am running a BACKEND Serverless project using the serverless-webpack plugin, developed with TypeScript, transpiled to JS by web pack, and deployed to AWS Lambda through the Serverless project. All was working well until I tried to pull in some of these odd Google Cloud SDK modules, and now I cannot run my services at all.

FYI: Serverless-webpack is something I am seeing more and more of in 2019.

The following line in webpack.config.js solves the problem to me btw:

module.exports = {
  ...
  externals: [ 'aws-sdk', 'commonjs2 firebase-admin' ],
  ...
};

Hi! Did you found any issue using this or is production safe?

Not at all. It’s working perfectly in production right now.

Had a similar issue, removed node_modules and reinstalled and it worked.

Having the same issue when running netlify-lambda and a TypeScript function:

WARNING in node_modules/hash-stream-validation/index.js
Module not found: Error: Can't resolve 'fast-crc32c' in 'node_modules/hash-stream-validation'
 @ node_modules/hash-stream-validation/index.js
 @ node_modules/@google-cloud/storage/build/src/file.js
 @ node_modules/@google-cloud/storage/build/src/index.js
 @ node_modules/firebase-admin/lib/storage/storage.js
 @ node_modules/firebase-admin/lib/firebase-namespace.js
 @ node_modules/firebase-admin/lib/default-namespace.js
 @ node_modules/firebase-admin/lib/index.js
 @ ./supervisor.ts

WARNING in node_modules/configstore/node_modules/write-file-atomic/index.js
Module not found: Error: Can't resolve 'worker_threads' in 'node_modules/configstore/node_modules/write-file-atomic'
 @ node_modules/configstore/node_modules/write-file-atomic/index.js
 @ node_modules/configstore/index.js
 @ node_modules/gcs-resumable-upload/build/src/index.js
 @ node_modules/@google-cloud/storage/build/src/file.js
 @ node_modules/@google-cloud/storage/build/src/index.js
 @ node_modules/firebase-admin/lib/storage/storage.js
 @ node_modules/firebase-admin/lib/firebase-namespace.js
 @ node_modules/firebase-admin/lib/default-namespace.js
 @ node_modules/firebase-admin/lib/index.js
 @ ./supervisor.ts

Any clue?

I found that I received this error in Next.js when I mingled my firebase-admin app with my firebase client side app. To solve it, I ensured that firebase-admin was never imported in a client-facing file, and then (and this is crucial) I separated the initialisation of the two apps so they were initialised in separate files.


Thank you so much! You saved my day!

For this solution, you need to definitely check this: https://colinhacks.com/essays/nextjs-firebase-authentication (I referred to this article)

I could find:

  • package version didn’t matter
  • initializing Firebase Client SDK and Firebase Admin SDK need to be separated
  • typeof window shouldn’t be undefined (as window object is in client-side - but Next.js runs Server-Side first) (Or it worked when typeof window === 'object')

And I could have solved the issue. My file structure and codes:

├── firebase/
│    ├── firebaseAdmin.ts
│    ├── firebaseClient.ts
│    └── firebaseConfig.ts
├── pages/
├── public/
├── styles/
// package.json

"dependencies": {
    "axios": "^0.21.1",
    "dotenv": "^10.0.0",
    "firebase": "^8.8.0",
    "firebase-admin": "^9.11.0",
    "next": "11.0.1",
    "nookies": "^2.5.2",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "@types/react": "17.0.15",
    "@typescript-eslint/eslint-plugin": "^4.29.0",
    "@typescript-eslint/parser": "^4.29.0",
    "eslint": "7.31.0",
    "eslint-config-next": "11.0.1",
    "eslint-plugin-react": "^7.24.0",
    "typescript": "4.3.5"
  }
// firebaseAdmin.ts

import * as firebaseAdmin from "firebase-admin";
import { firebaseAdminConfig } from "./firebaseConfig";

if (!firebaseAdmin.apps.length) {
	firebaseAdmin.initializeApp({
		credential: firebaseAdmin.credential.cert(firebaseAdminConfig)
	});
}

export { firebaseAdmin };
// firebaseClient.ts

import "firebase/auth";
import firebaseClient from "firebase/app";
import { firebaseClientConfig } from "./firebaseConfig";


if (typeof window !== "undefined" && !firebaseClient.apps.length) {    // ********** NOTE  **********
	firebaseClient.initializeApp(firebaseClientConfig);
	firebaseClient
		.auth()
		.setPersistence(firebaseClient.auth.Auth.Persistence.SESSION);
	(window as any).firebase = firebaseClient;
}

export { firebaseClient };
// firebaseConfig.ts

export const firebaseClientConfig = {
	apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
	authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
	projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
	storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
	messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
	appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
};


export const firebaseAdminConfig = {
	privateKey: process.env.NEXT_PUBLIC_FIREBASE_PRIVATE_KEY,
	clientEmail: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_EMAIL,
	projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID
};

(I’ve made an .env.local file and then saved those keys)

+) you don’t have to modify this file, but my setting for next.config.js

// eslint-disable-next-line no-undef
module.exports = {
	webpack: (config, { isServer }) => {
		if (!isServer) {
			config.resolve.fallback.fs = false;
			config.resolve.fallback.child_process = false;
			config.resolve.fallback.request = false;
			config.resolve.fallback.net = false;
			config.resolve.fallback.worker_threads = false;
			config.resolve.fallback.tls = false;
		}
		return config;
	}
};

I wish this could be a help

I’m building a NextJS app using “next-firebase-auth”, and ran into this issue. My deploys were building fine, but then this started popping up. The way I fixed the issue:

  • I applied #84
  • I ran npm install --save fast-crc32c
  • Then the error changed, and I had to run npm i retry-request request

This was able to fix my deploys, let me know if it works for y’all

@IamMasterWayne

The Firebase Admin SDK is a server only library, the errors you are seeing are due to this. If you need to do admin operations, you need to do it in a trusted environment and expose it via an API of some kind (lambda, rest etc etc).

In my project i used the npm package: "firebase-admin" for accessing the firestore object like this: import { firestore } from "firebase-admin";

But firestore can also be imported like this: import firestore from '@react-native-firebase/firestore';

I removed the "firebase-admin" package and my problem was solved:)

This was on a brand new repo. Should I have to install dependencies by hand? That doesn’t seem right.