firebase / firebase-admin-node

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

firebase-admin dependency errors #84

Closed esparkman closed 7 years ago

esparkman commented 7 years ago

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
katowulf commented 7 years ago

Are those dependencies in fact installed? Is ./~/.../ the right path when referenced from build/dev-server.js? What does the yarn config file look like? There's a lot more to include here before we can help with debugging.

esparkman commented 7 years ago

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

hiranya911 commented 7 years ago

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.

crossRT commented 6 years ago

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?

cactoo commented 6 years ago

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

crossRT commented 6 years ago

@ixjakub sorry for late reply. No, I didn't find any solution eventually. But I drop the use of typescript, and then it works like charm.

aaaguirrep commented 5 years ago

Hi, did you find any solutions? I have the same issue.

FredrikNoren commented 5 years ago

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

aaaguirrep commented 5 years ago

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:

huy-lv commented 5 years ago

Why is this issue closed? I got the same problem with this dependency

    "firebase": "^5.5.3",
    "firebase-admin": "^6.5.0",
aaaguirrep commented 5 years ago

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.

redaben commented 5 years ago

@ixjakub Did you find a solution ? I have the same pb running firebase-admin with netlify functions

cactoo commented 5 years ago

I finally turned away from Firebase at all. I can't help you.

chinchang commented 5 years ago

@hiranya911 Any update on this issue? Facing the same error.

hiranya911 commented 5 years ago

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.

ts-machine commented 5 years ago

@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.

hiranya911 commented 5 years ago

The error message is complaining about built-in Node packages like fs and net:

* 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

We don't declare them explicitly, but expect the Node.js environment to provide them. I don't know how to "fix" firebase-admin so it can resolve these built-ins. If anybody knows of a fix, or provide some pointers I'd be happy to take a look.

The solution to this problem most likely exists in the webpack domain. According to Google search there are many similar issues reported agains various other libraries, with no specific resolution in sight. But the following issue discusses several potential fixes, that seem to have fixed a similar issue to some: https://github.com/mysqljs/mysql/issues/1563

amit00978 commented 5 years ago

After installed "firebase-admin": "^8.3.0" it gives an error While trying to resolve module `fs . any help really appreciated.

amalshehu commented 4 years ago

Having the same issue, Why it looks closed ? @esparkman

antoinerousseau commented 4 years ago

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?

rodrigogs commented 4 years ago

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

module.exports = {
  ...
  externals: [ 'aws-sdk', 'commonjs2 firebase-admin' ],
  ...
};
majindageta commented 4 years ago

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?

rodrigogs commented 4 years ago

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.

bartkoedijk commented 4 years ago

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:)

IamMasterWayne commented 4 years ago

"react": "^16.13.1" "firebase": "^7.19.1" "firebase-admin": "^9.1.1"

_./nodemodules/hash-stream-validation/index.js Module not found: Can't resolve 'fast-crc32c'

_./node_modules/configstore/nodemodules/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

Gibbo3771 commented 3 years ago

@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).

advantage-software commented 3 years ago

"react": "^16.13.1" "firebase": "^7.19.1" "firebase-admin": "^9.1.1"

_./nodemodules/hash-stream-validation/index.js Module not found: Can't resolve 'fast-crc32c'

_./node_modules/configstore/nodemodules/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

Do you find a solution to this?

AaronLayton commented 3 years ago

I am getting this same error, what ever it is, user error or package error, it is obvious this is not clear to the end user

asset bundle.js 20.8 MiB [compared for emit] (name: main)
runtime modules 1.37 KiB 6 modules
modules by path ./node_modules/ 8.05 MiB
  javascript modules 7.73 MiB 578 modules
  json modules 329 KiB
    modules by path ./node_modules/google-gax/ 39.4 KiB 7 modules
    modules by path ./node_modules/@google-cloud/ 78 KiB 6 modules
    modules by path ./node_modules/protobufjs/ 10 KiB 4 modules
    modules by path ./node_modules/ent/ 54 KiB
      ./node_modules/ent/reversed.json 22.3 KiB [built] [code generated]
      ./node_modules/ent/entities.json 31.7 KiB [built] [code generated]
modules by path ./src/*.ts 1.41 KiB
  ./src/index.ts 1.07 KiB [built] [code generated]
  ./src/firebase-admin-instance.ts 353 bytes [built] [code generated]
27 modules

WARNING in ./node_modules/hash-stream-validation/index.js 5:8-30
Module not found: Error: Can't resolve 'fast-crc32c' in 'D:\Projects\Git\ibms-mqtt-watcher\node_modules\hash-stream-validation'
 @ ./node_modules/@google-cloud/storage/build/src/file.js 26:29-62
 @ ./node_modules/@google-cloud/storage/build/src/index.js 20:13-30
 @ ./node_modules/firebase-admin/lib/storage/storage.js 55:22-62
 @ ./node_modules/firebase-admin/lib/firebase-namespace.js 225:26-62
 @ ./node_modules/firebase-admin/lib/default-namespace.js 19:27-58
 @ ./node_modules/firebase-admin/lib/index.js 19:15-45
 @ ./src/firebase-admin-instance.ts 1:0-40 3:5-22 4:4-23 5:20-41 11:15-20
 @ ./src/index.ts 2:0-46 22:4-19

WARNING in ./node_modules/retry-request/index.js 73:21-39
Module not found: Error: Can't resolve 'request' in 'D:\Projects\Git\ibms-mqtt-watcher\node_modules\retry-request'
 @ ./node_modules/google-gax/build/src/streamingCalls/streaming.js 22:21-45
 @ ./node_modules/google-gax/build/src/index.js 62:18-55
 @ ./node_modules/@google-cloud/firestore/build/src/index.js 401:95-121 1067:37-71 1348:15-43
 @ ./node_modules/firebase-admin/lib/firebase-namespace.js 242:28-62
 @ ./node_modules/firebase-admin/lib/default-namespace.js 19:27-58
 @ ./node_modules/firebase-admin/lib/index.js 19:15-45
 @ ./src/firebase-admin-instance.ts 1:0-40 3:5-22 4:4-23 5:20-41 11:15-20
 @ ./src/index.ts 2:0-46 22:4-19

2 warnings have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

I am only importing the firebase-admin into a NodeJS app and attempting to send a notification. It is TypeScript if that affects anything

import * as admin from "firebase-admin";
var serviceAccount = require("../serviceAccountKey.json");

if (!admin.apps.length) {
    admin.initializeApp({
        credential: admin.credential.cert(serviceAccount)
    });
}

export default admin;
import admin from './firebase-admin-instance'

const payload = {
    notification: {
        title: "Server says there is a problem",
        message: "Some issue happened at " + new Date().getTime()
    }
};

admin.messaging().sendToDevice(dummyAccounts, payload)
.then(function(response) {
    console.log("Successfully sent message:", response);
})
.catch(function(error) {
    console.log("Error sending message:", error);
});
hiranya911 commented 3 years ago

Today, you cannot use firebase-admin in Webpack without externalizing it. You will have to apply a workaround like the one mentioned here: https://github.com/firebase/firebase-admin-node/issues/84#issuecomment-630311771

AaronLayton commented 3 years ago

@hiranya911 I got it working without externalizing it. I have currently got the following installed

"@firebase/app": "^0.6.27",
"firebase-admin": "^9.10.0"

I used the below to import firebase - note the import * as admin

import * as admin from "firebase-admin";

The most I get now are warnings that I can't find a npm installed version of these packages so falls back to local versions of them (assume shipped by firebase)

2021-06-28_18h54_50
hiranya911 commented 3 years ago

Thanks for sharing this @AaronLayton. I suppose the fix you did here is to install @firebase/app along side firebase-admin. It's not a runtime dependency for Admin SDK, but Webpack thinks it is. If you were to use firebase-admin without installing other dependencies you will have to externalize it.

div-cowboy commented 3 years ago

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:

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

moschan commented 3 years ago

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
  }
}
SeiwonPark commented 3 years ago

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
  }
}

exactly followed installed versions but didn't work for me :(

says:

Module not found: Error: Can't resolve 'fast-crc32c'

65536william commented 3 years ago

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.

SeiwonPark commented 3 years ago

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:

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

kevincoleman commented 3 years ago

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:)

Thank you for sharing this @bartkoedijk! I was pulling hair out over this one, and your comment saved me.