Firebase-tools: Deploy Error: Function load error: Code in file index.js can't be loaded

Created on 19 Oct 2017  Â·  39Comments  Â·  Source: firebase/firebase-tools

I am trying to deploy my functions to firebase, yesterday I was able to do it just fine, but today I just can't get it done. The cli tells me it can't find firebase-admin module, which is listed in the package.json dependencies and is installed. I have done nothing since yesterday to make it stop working, I tried updating firebase-functions to the newest version(0.7.1), but the error persisted.

Version info

Node.js version: 6.11.2
firebase-tools version: 3.13.1
firebase-admin version: 5.4.2
firebase-functions version: 0.5.7

Steps to reproduce

firebase deploy --only functions -P prod

Expected behavior

Functions deployed succesfully.

Actual behavior

Functions get deployed with errors, the cli shows me the following message:

Deploy Error: Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase-admin'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/user_code/node_modules/firebase-functions/lib/apps.js:25:16)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

My package.json (PS: I have firebase here, the client module, because I need to send reset password emails, which are not supported yet by the firebase-admin SDK (https://github.com/firebase/firebase-admin-node/issues/46):

{
"name": "functions",
"description": "Cloud Functions for Firebase",
"version": "0.0.12",
"dependencies": {
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"express": "^4.15.4",
"firebase": "^4.5.2",
"firebase-admin": "^5.4.2",
"firebase-functions": "^0.7.1",
"mercadopago": "^0.5.0"
},
"private": true
}

Most helpful comment

I'm getting a similar issue but for 'express' module.

Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/user_code/index.js:6:15)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

Firebase:
"firebase-admin": "~5.8.1",
"firebase-functions": "^0.8.1"

I tried doing this:
npm install --save-exact [email protected] npm install --save-exact [email protected],
but I got the following error :
_Error: Error occurred while parsing your function triggers. Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder._

All 39 comments

I'm encountering the same issue. My local packages versions are:

├─┬ [email protected]
├─┬ [email protected]
$ firebase --version
3.13.1

I'm having the same exact problem, with the same versions of packeges. It seems more like a server failure than code, because minutes ago I was able to upload just fine, but now I get the same error over and over again.

@nobuhito Suggested workaround only works for me when npm cache is cleared before:

npm cache clear --force && npm install --save-exact [email protected] npm install --save-exact [email protected]

But.. it works for now, can deploy my functions again.

GCF had a backend problem installing [email protected]. This has been resolved and your functions should work now. Please reopen if you continue to have issues.

Looks like this issue is back

@stevejcox which version of firebase-admin are you having this issue with? Can you paste your logs?

"firebase-admin": "^5.4.1",
"firebase-functions": "^0.7.0"

Debug log at: https://gist.github.com/stevejcox/949e2d960c1dd02b927a7372f8817ac6

It's inconsistent on which functions successfully deploy and which fails. Seems different each time I try to deploy.

Same here

+1

"firebase-admin": "~5.4.0",
"firebase-functions": "^0.7.0"

Functions have been taking abnormally long to deploy all day, and the issue started happening an hour ago.

+1
"firebase-admin": "^5.2.1",
"firebase-functions": "^0.7.3",

+1

package.json
"firebase-admin": "^5.4.2", "firebase-functions": "^0.7.1"

firebase-tools: 3.15.4

Thanks all for the reports. Indeed there's a production issue right now. We're investigating; stay tuned! https://status.firebase.google.com/incident/Functions/17027

Same issue with -
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1",

@JoeOsterfeld @benka @faahmad @MchlG Thanks for bearing with us, can you confirm whether or not you're able to deploy your functions now?

It worked for me, thanks!

@justinrosenthal I can successfully deploy now, thanks!

Yes has been working for me too - was only down for about 30-45 min. Sorry
for late reply

On Thu, Nov 30, 2017 at 7:49 PM, Faraz Ahmad notifications@github.com
wrote:

@justinrosenthal https://github.com/justinrosenthal I can successfully
deploy now, thanks!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-tools/issues/515#issuecomment-348368486,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ATugE9VAxCG43zXRh9qFGMDJNciOJiA6ks5s700JgaJpZM4P-mpM
.

Sounds great. Closing the issue.

I'm getting a similar issue but for 'express' module.

Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/user_code/index.js:6:15)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

Firebase:
"firebase-admin": "~5.8.1",
"firebase-functions": "^0.8.1"

I tried doing this:
npm install --save-exact [email protected] npm install --save-exact [email protected],
but I got the following error :
_Error: Error occurred while parsing your function triggers. Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder._

I made a simple http request function and I am also facing the same problem:

//+======================================================
//    Code for doing HTTP GET Request to get Live Scores.
//+======================================================

exports.fetch_live_score = functions.https.onRequest((req, res) => {

    var url = "http://livescore-api.com/api-client/scores/live.json?key="
                + LIVE_SCORE_API_KEY + "&secret=" + LIVE_SCORE_API_SECRET;

    return request(url, function (error, response, body){
        var data = JSON.parse(body);
        response.status(200).send(data);
    })

});

These are my dependencies:

    "firebase-admin": "~5.8.1",
    "firebase-functions": "^0.8.1"

I resolved the issue by adding "request": "^2.83.0" in package.json file.

this issue still persist

Function load error: Code in file lib/index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module '@firebase/app'
    at Function.Module._resolveFilename (module.js:476:15)
    at Function.Module._load (module.js:424:25)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.observable (/user_code/lib/index.js:1542:18)
    at __webpack_require__ (/user_code/lib/index.js:20:30)
    at Object.<anonymous> (/user_code/lib/index.js:4477:72)
    at __webpack_require__ (/user_code/lib/index.js:20:30)
    at Object.<anonymous> (/user_code/lib/index.js:7742:20)
    at __webpack_require__ (/user_code/lib/index.js:20:30)

  "firebase-admin": "~5.12.0",
    "firebase-functions": "^1.0.2",

@kamilo81 your package.json includes firebase-admin but you are trying to require @firebase/app. For Cloud Functions you should usually be using the Admin SDKs, not trying to require the client ones.

Ok had this issue. like the error message said, did you missed the dependency you need in package.json

I installed express without --save so it didn't get added to package.json and thats why it complains about this error. Hope it help.

So instead of npm install express it should have been npm install --save express

Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'express'

I also have same problem

Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'redis'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/srv/index.js:3:15)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)


Functions deploy had errors with the following functions:
    counterTaxi


To try redeploying those functions, run:
    firebase deploy --only functions:counterTaxi


To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.

Having trouble? Try firebase deploy --help

I remember I have Redis as one of my depedencies, but i don't know how to put it inside my package.json

@Yosafat1997 you may have to run npm install --save redis in your functions folder to add the redis dependency to the package.json. If you're still having trouble, please open a new issue.

Im getting the same error ( used this tutorial https://hackernoon.com/deploying-angular-universal-v6-with-firebase-c86381ddd445 )

âš  functions[ssr(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase/app'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.firebase/app (/srv/dist/server/main.js:4218:18)
at __webpack_require__ (/srv/dist/server/main.js:20:30)
at Object../src/app/services/authentication.service.ts (/srv/dist/server/main.js:3490:13)
at __webpack_require__ (/srv/dist/server/main.js:20:30)
at Object../src/app/app.component.ts (/srv/dist/server/main.js:2533:32)
at __webpack_require__ (/srv/dist/server/main.js:20:30)

my versions are
"firebase-admin": "^8.0.0",
"firebase-functions": "^3.0.0"

Please help, thanks.

@RahulGuptaIIITA Please run npm install --save firebase in your functions folder.

@laurenzlong Im following this tutorial
https://hackernoon.com/deploying-angular-universal-v6-with-firebase-c86381ddd445

and now im seeing

Screen Shot 2019-08-12 at 7 31 13 PM

Not sure why? Do you know what I could have done wrong?

Hi, I don't think that's a bug with firebase-tools. Could you please file an issue in the Github repository for the tutorial? https://github.com/aaronte/angular-universal-firebase

Had this issue with a @types/... module.
Workaround: add the non-typed module to package.json

my package.json

"dependencies": {
  "@types/request": "^2.48.2",
  "request": "^2.88.0"    // unused
}

I tried install the required module(expo-server-sdk in my case) in the functions folder and it's working now!!

Are you deploying fuction in proper folder?

I have the same issue but the problem is with a module I defined myself in my code:

Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded. Did you list all required modules in the package.json dependencies? Detailed stack trace: Error: Cannot find module '../db/Adapter'

ok find the problem. In my specific case it was that I renamed my module from adapter.ts to Adapter.ts and lib/Adapter.js was not being generated on npm run build so I needed to delete lib/* re-build and then I was able to successfully firebase deploy --only functions!

I have the same issue I am trying to deploy one of my firebase function it's deploying properly a few mins after I try to deploy the same functions getting this error.

Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'protractor'

But this looks like different!

It happened to me as well, then I noticed there is one dependency I thought I installed,
but actually I need to go folder functions and do npm install --save [dependency].

Then it worked for me.

It happened to me as well, then I noticed there is one dependency I thought I installed,
but actually I need to go folder functions and do npm install --save [dependency].

Then it worked for me.

What dependency you installed in the function folder

Was this page helpful?
0 / 5 - 0 ratings