Berry Blue
Berry Blue

Reputation: 16482

Firebase Error: function terminated. Recommended action: inspect logs for termination reason

I tried updating some cloud functions to Firebase that were working earlier but I'm getting odd errors. These are the errors I get for each of my functions in my main index.js file.

Deployment error.
Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.

When I look at my logs I see these errors.

Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging Function cannot be initialized.

The documentation at the next suggested resource is very generic. How do I do additional logging to find the problem? I can run my code locally fine so I'm not sure why it won't deploy to Firebase.

I believe the problem may be from requiring a JSON file as a module. This works fine locally but does Firebase support this feature?

const config = require('./config.json');

Upvotes: 5

Views: 5837

Answers (1)

Jere Schneider
Jere Schneider

Reputation: 1206

sorry for my English, I speak Spanish but I'm going to try my best so you can understand me.

I'm not an expert in NodeJS but I had the same error, my problem was that I add the dependencies in "devDependencies" but they have to go on "dependencies" then we go into the project "functions" (in case of firebase) and execute in your console the next command npm i and next npm ci after we do all of this we make the deploy normally.

You can see the complete log: execute with the next command in your console firebase functions:log --only nameYourFunction and search the next sentence "Detailed stack trace: Error: Cannot find module" Then it will tell you which is the module that has the conflict and the log contain more information.

References:

https://docs.npmjs.com/cli/v7/commands/npm-ci

https://github.com/npm/npm/issues/16866

Upvotes: 13

Related Questions