Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy Error: Function load error: Code in file index.js can't be loaded #515

Closed
dungahk opened this issue Oct 19, 2017 · 41 comments
Closed

Comments

@dungahk
Copy link

dungahk commented Oct 19, 2017

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 (firebase/firebase-admin-node#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
}

@Quramy
Copy link

Quramy commented Oct 19, 2017

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

├─┬ firebase-admin@5.4.2
├─┬ firebase-functions@0.7.1
$ firebase --version
3.13.1

@HegarGarcia
Copy link

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
Copy link

see Firebase Status Dashboard

https://status.firebase.google.com/incident/Functions/17024

@skizzo
Copy link

skizzo commented Oct 19, 2017

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

npm cache clear --force && npm install --save-exact firebase-functions@0.7.0 npm install --save-exact firebase-admin@5.4.0

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

@inlined
Copy link
Member

inlined commented Oct 23, 2017

GCF had a backend problem installing firebase-admin@5.4.2. This has been resolved and your functions should work now. Please reopen if you continue to have issues.

@inlined inlined closed this as completed Oct 23, 2017
@stevejcox
Copy link

Looks like this issue is back

@laurenzlong
Copy link
Contributor

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

@stevejcox
Copy link

stevejcox commented Nov 30, 2017

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

@viniciusd
Copy link

Same here

@JoeOsterfeld
Copy link

JoeOsterfeld commented Nov 30, 2017

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

@benka
Copy link

benka commented Nov 30, 2017

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

@faahmad
Copy link

faahmad commented Nov 30, 2017

+1

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

firebase-tools: 3.15.4

@rjhuijsman
Copy link
Contributor

rjhuijsman commented Nov 30, 2017

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

@MchlG
Copy link

MchlG commented Nov 30, 2017

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

@kmcnellis kmcnellis reopened this Nov 30, 2017
@justinrosenthal
Copy link

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

@specie
Copy link

specie commented Nov 30, 2017

It worked for me, thanks!

@faahmad
Copy link

faahmad commented Dec 1, 2017

@justinrosenthal I can successfully deploy now, thanks!

@MchlG
Copy link

MchlG commented Dec 4, 2017 via email

@inlined
Copy link
Member

inlined commented Dec 4, 2017

Sounds great. Closing the issue.

@inlined inlined closed this as completed Dec 4, 2017
@malick7
Copy link

malick7 commented Feb 7, 2018

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 firebase-functions@0.7.0 npm install --save-exact firebase-admin@5.4.0,
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.

@Shajeel-Afzal
Copy link

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"

@Shajeel-Afzal
Copy link

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

@piuskamil
Copy link

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",

@mbleigh
Copy link
Contributor

mbleigh commented Jul 2, 2018

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

@cjmling
Copy link

cjmling commented Apr 26, 2019

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'

@Yosafat1997
Copy link

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

@bkendall
Copy link
Contributor

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

@RahulGuptaIIITA
Copy link

RahulGuptaIIITA commented Aug 10, 2019

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.

@laurenzlong
Copy link
Contributor

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

@RahulGuptaIIITA
Copy link

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

@laurenzlong
Copy link
Contributor

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

@Hulkermon
Copy link

Hulkermon commented Aug 28, 2019

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
}

@DaniPB
Copy link

DaniPB commented Feb 15, 2020

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

@AdamTrybus
Copy link

Are you deploying fuction in proper folder?

@bernardo-martinez
Copy link

bernardo-martinez commented May 30, 2020

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

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

@bernardo-martinez
Copy link

bernardo-martinez commented May 30, 2020

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!

@sandygit17
Copy link

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!

@chiafengtsai
Copy link

chiafengtsai commented Aug 11, 2020

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.

@sandygit17
Copy link

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

@cafe4it
Copy link

cafe4it commented Apr 4, 2021

same issue
error logs:

2021-04-04T14:30:31.616794Z N api: 
2021-04-04T14:31:28.341Z ? api: Provided module can't be loaded.
2021-04-04T14:31:28.341Z ? api: Did you list all required modules in the package.json dependencies?
2021-04-04T14:31:28.341Z ? api: Detailed stack trace: Error: Cannot find module 'firebase-functions'

functions/package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "10"
  },
  "main": "index.js",
  "dependencies": {
    "@hapi/hapi": "^20.1.2",
    "firebase-admin": "^9.2.0",
    "firebase-functions": "^3.13.2",
    "lodash": "^4.17.20"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

@inlined
Copy link
Member

inlined commented Apr 6, 2021

  1. This is a really old bug and was based on a preview version of the SDK. While I think it's quite commendable that you searched for duplicates, I don't think this would share the same root case.
  2. Have you tried running npm install before calling firebase deploy? It looks like your definition is correct so that seems to be the best answer
  3. Have you contacted Firebase support? If you are having problems using the product (as opposed to believing there is a bug with the product) then this is the right place for you. You'll get faster response times and customer support trends are bubbled up to the engineering team to triage and steer us towards UX improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests