node: v.8.16.2
firebase-functions: 3.3.0
firebase-tools: 7.10.0
firebase-admin: 8.9.0
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
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.
Getting the envs from .runtimeconfig.json in case is development, otherwise get it from functions.config() method.
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)
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
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/issues
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!
@andieromero I'm trying to call it on the server via CI/CD pipeline, calling directly through the node exec or using an import from firebase-admin and both haven't worked.
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 I solved it updating the next package to "latest" and using env property in my next.config.js file. This way you can pass env variables into your Firebase project without the needed of functions config method.
https://nextjs.org/docs/api-reference/next.config.js/environment-variables
@cmlbrnc I solved it updating the
nextpackage to "latest" and usingenvproperty in mynext.config.jsfile. This way you can pass env variables into your Firebase project without the needed of functions config method.https://nextjs.org/docs/api-reference/next.config.js/environment-variables
I dont use functions config method. I use ``import admin from "firebase-admin";
try {
admin.initializeApp({
credential: admin.credential.cert({
project_id: process.env.project_id,
private_key: process.env.private_key,
client_email: process.env.client_email,
}),
databaseURL: "https://....",
});
} catch (error) {
/*
* We skip the "already exists" message which is
* not an actual error when we're hot-reloading.
*/
if (!/already exists/u.test(error.message)) {
// eslint-disable-next-line no-console
console.error("Firebase admin initialization error", error.stack);
}
}
export default admin.firestore();
@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
@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.
@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 ;)
Thanks everyone for your comments.
I'm building a new project using firebase-admin with Next.js and in their examples they import it only on server-side.
So, @cmlbrnc, you should check your code. Maybe these examples can help you.
https://github.com/vercel/next.js/tree/canary/examples/with-firebase
https://github.com/vercel/next.js/tree/canary/examples/with-firebase-hosting
https://github.com/vercel/next.js/tree/canary/examples/with-firebase-authentication
Regards.
Most helpful comment
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.