firebase-functions: Module not found: Can't resolve 'child_process' in google-auth-library
Related issues
- https://github.com/firebase/firebase-functions/issues/69
- https://github.com/googleapis/google-auth-library-nodejs/issues/150
- https://stackoverflow.com/questions/44305603/types-node-installed-typescript-version-not-able-find-module-child-process
- https://github.com/webpack/webpack-dev-server/issues/66
[REQUIRED] Version info
node: v.8.16.2
firebase-functions: 3.3.0
firebase-tools: 7.10.0
firebase-admin: 8.9.0
[REQUIRED] Test case
Here’s a simple example of this code, It’s just as it is! The only problem is to get the functions config(). https://codesandbox.io/s/exciting-leftpad-l27tt
[REQUIRED] Steps to reproduce
Try to get the Firebase hosting env variables via code, and get the child_process
error for /node_modules/google-auth-library/build/src/auth
.
'm trying to call it on the client via CI/CD pipeline, calling directly through the node exec or using an import from firebase-admin and both haven’t worked.
[REQUIRED] Expected behavior
Getting the envs from .runtimeconfig.json
in case is development, otherwise get it from functions.config()
method.
[REQUIRED] Actual behavior
Could not find files for /index in .next/build-manifest.json
ModuleNotFoundError: Module not found: Error: Can't resolve 'child_process' in '/home/myproject/node_modules/google-auth-library/build/src/auth'
at factory.create (/home/myproject/node_modules/webpack/lib/Compilation.js:925:10)
at factory (/home/myproject/node_modules/webpack/lib/NormalModuleFactory.js:401:22)
at resolver (/home/myproject/node_modules/webpack/lib/NormalModuleFactory.js:130:21)
at asyncLib.parallel (/home/myproject/node_modules/webpack/lib/NormalModuleFactory.js:224:22)
at /home/myproject/node_modules/neo-async/async.js:2830:7
at /home/myproject/node_modules/neo-async/async.js:6877:13
at normalResolver.resolve (/home/myproject/node_modules/webpack/lib/NormalModuleFactory.js:214:25)
at doResolve (/home/myproject/node_modules/enhanced-resolve/lib/Resolver.js:213:14)
at hook.callAsync (/home/myproject/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
at _fn0 (eval at create (/home/myproject/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
at resolver.doResolve (/home/myproject/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7)
at hook.callAsync (/home/myproject/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
at _fn0 (eval at create (/home/myproject/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
at hook.callAsync (/home/myproject/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
at _fn0 (eval at create (/home/myproject/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
at resolver.doResolve (/home/myproject/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43)
Were you able to successfully deploy your functions?
I’m not able to deploy it if I want to get Firebase envs from functions config() method.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19
I am using react next.js and getting the same error. If I don’t use firestore, I have to transfer my data to mongoDb.
@cmlbrnc @syedfaizan I had the exact same issue and I finally found out what the issue was by pasting my code into https://next-code-elimination.now.sh/. The issue was that my firebase-admin import wasn’t being eliminated by the client-side, leading to the code being run in the browser and causing this error. In my case, the import wasn’t eliminated because it was unused, so simply using it in getServersideProps fixed the error.
I had this problem too with NextJS. It was happening because
child_process
, a NodeJS API, was being invoked in the browser. You should only useadmin
ingetStaticProps
,getServerSideProps
, or in an API route handler, i.e., in functions that only run on the server, whereadmin
comes fromimport * as admin from 'firebase-admin';
. If you only useadmin
in functions that run on the server, NextJS is smart enough to not include thefirebase-admin
dependency in the client bundle, ensuring that none of its NodeJS-specific code will be executed in the browser.@cmlbrnc Coincidence much, Im using the same setup and stuck at the same spot, and if this doesnt work i have to go back to mongodb storage
@8q16d I had the same issue and just resolved thanks to your comment. There was
import { ... } from 'firebase-admin'
instead of'firebase'
(because I carelessly copied it from node.js project). Guys you’d better check for your imports 😉I dont use functions config method. I use ``import admin from “firebase-admin”;
}
export default admin.firestore();
I’m getting this too, followed all the Firebase Docs and Firebase-Functions doc, still missing stuff. I comment out “firebase-functions” and “firebase-admin” and it builds just fine. So what gives with Webpack and Firebase-functions?
Update - these are server side packages - DO NOT ADD/IMPORT Them to client side and try to render with webpack, it will fail.
Hi, is this being called on the client? If you only require
firebase-admin
and it still fails then file a bug in https://github.com/firebase/firebase-admin-node/issuesimport { FieldValue } from '@google-cloud/firestore';
Was the culprit for me.
Hey @francisrod01. We need more information to resolve this issue but there hasn’t been an update in 7 weekdays. I’m marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!