cloud-functions-emulator icon indicating copy to clipboard operation
cloud-functions-emulator copied to clipboard

Can't serve firebase-functions locally

Open Kar1Huang opened this issue 7 years ago • 34 comments

[email protected] [email protected] [email protected] [email protected] node@8.*

run firebase serve --only functions

output:

i  functions: Preparing to emulate functions.
Warning: You're using Node.js v8.1.3 but Google Cloud Functions only supports v6.11.5.
⚠  functions: Failed to emulate helloWorld

while if i switch to node@6.*

⚠  functions: Cannot start emulator. Error: Cannot find module '/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/node-v48-darwin-x64-unknown/grpc_node.node'

when i go to /usr/local/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary i only got node-v57-darwin-x64-unknown instead of node-v48-darwin-x64-unknown

Kar1Huang avatar Dec 15 '17 05:12 Kar1Huang

I have a very similar issue, get error message:

Node.js v6.11.x or greater is required to run the Emulator! ⚠ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory. ⚠ functions: Error from emulator. Error: Emulator crashed! Check the log file...

Running node 6.11.1 via nvm. The log file does not add anything. I have also run the command suggested above and tried all suggestions on the page: https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/Troubleshooting

"dependencies": { "azure": "^2.2.1-preview", "firebase-admin": "~5.4.0", "firebase-functions": "^0.7.4", "request": "^2.83.0", "request-promise": "^4.2.2", "secure-compare": "^3.0.1", "web3": "^1.0.0-beta.24" },

I am able to deploy the functions fine and they work? This is really frustrating, Thanks.

craigvl avatar Dec 19 '17 12:12 craigvl

same issue here:

Win7 Ent x64

[email protected]
"firebase-admin": "^5.5.0",
"firebase-functions": "^0.7.5"

No errors in the firebase-debug.log file except:

[warn] ! functions: Failed to emulate hello

flado avatar Jan 05 '18 01:01 flado

same issue with:

"firebase-admin": "^5.6.0",
"firebase-functions": "latest"

console messages:

i functions: Preparing to emulate functions. i hosting: Serving hosting files from: public

  • hosting: Local server: http://localhost:5000

! functions: Failed to emulate hello

flado avatar Jan 05 '18 02:01 flado

Similar issue in a fresh project

[email protected] [email protected] [email protected] [email protected] [email protected]

output:

Node.js v6.11.x or greater is required to run the Emulator! 
functions: Error from emulator. Error: Emulator crashed! Check the log file...

pamartineza avatar Jan 19 '18 13:01 pamartineza

Guys, I seemed to fix my issue, I am not quite sure which command fixed it but below are some that I ran.

  • Deleted node modules for functions
  • nvm install node --reinstall-packages-from=node
  • nvm use 6.11.5
  • nvm alias default 6.11.5
  • npm install -g firebase-tools
  • sudo install -g n
  • sudo n latest
  • npm install

Like I said I I don't know which of the above was the fix and the order is not correct but just putting here as it may help someone else. I think that getting the terminal using 6.11.5 is the key.

craigvl avatar Jan 20 '18 03:01 craigvl

Using nvm. The move from 6.11.1 to 6.11.5 resolved this for me.

wooliet avatar Jan 20 '18 03:01 wooliet

In my case moving to v6.12.3 fixed the problem, I think the main problem is that the official documentation isn't up to date and is pointing to a wrong version

pamartineza avatar Jan 20 '18 14:01 pamartineza

I tried using nvm for 6.11.5 and cloud functions still fail to emulate locally :(

foush avatar Jan 26 '18 06:01 foush

Okay so what finally worked for me is going into this dir: ~/.config/configstore/ and then deleting everything to do with @google-cloud and firestore*.json. Then I went back into the console and did a firebase login, I think what's happening is the token is expiring and it's not refreshing it our your user it getting dropped, something in that universe. Very annoying.

shaunc869 avatar Feb 27 '18 19:02 shaunc869

Okay so just another note, I am able to repeat the cause and fix here. So in my case I am trying to debug the functions in VS Code, so I followed this guide:

https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/Debugging-with-Visual-Studio-Code

When I run functions start and then functions deploy api in my case I get an error:

ERROR: Function load error: Code could not be loaded.
ERROR: Does the file exists? Is there a syntax error in your code?
ERROR: Detailed stack trace: module.js:471
    throw err;
    ^

And then if I then try to run:

firebase serve --only functions

I get:

i  functions: Preparing to emulate functions.
⚠  functions: Failed to emulate api

And at this point I go into ~/.config/configstore/ and delete the @google-cloud folder and firestore json file, then drop back into the console and run:

firebase login (go through the login process) and then finally firebase use project-name and then firebase serve --only functions works fine again.

Hope this helps someone and I hope this gets fixed, I would really like to use VSCode to debug this stuff. Thanks!

June-04-2018 UPDATE:

I ran into this issue again when trying to run an API that was enabled, in this case it was the natural language API, I got the error:

Error: 7 PERMISSION_DENIED: Cloud Natural Language API has not been used in project XXXXXX before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/language.googleapis.com/overview?project=XXXXXXXX then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

Of course that project ID doesn't go any where and of course the API was enabled, turns out this fix also works for this error, just wanted to add it since apparently you get here at least 2 different ways.

shaunc869 avatar Feb 28 '18 16:02 shaunc869

Thanks @shaunc869 -- fixed my issue.

jeffreywescott avatar Mar 04 '18 20:03 jeffreywescott

I deleted ~/.config/configstore/@google-cloud and that fixed it for me. I didn't have to login or use.

abraham avatar May 16 '18 15:05 abraham

What is Windows 10 equivalent folder path to ~/.config/configstore/@google-cloud?

paritosh149 avatar Jun 11 '18 11:06 paritosh149

@paritosh149 c:\users<your username.config\configstore@google-cloud

Anyway, in my case deleting this folder did not resolve the problem

realtebo avatar Jun 16 '18 08:06 realtebo

I just discovered the --debug options, than I run firebase deploy --only functiotions -debug and I got this

[2018-06-16T09:06:49.437Z] Parsing function triggers
[2018-06-16T09:06:50.197Z] Error while deploying to emulator: RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received 2858637923
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received 2858637923
    at checkInt (internal/buffer.js:35:11)
    at writeU_Int32LE (internal/buffer.js:515:3)
    at Buffer.writeInt32LE (internal/buffer.js:684:10)
    at Object.entryHeaderToBinary (C:\Users\mirko\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\adm-zip\headers\entryHeader.js:216:18)
    at Object.packHeader (C:\Users\mirko\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\adm-zip\zipEntry.js:260:39)
    at C:\Users\mirko\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\adm-zip\zipFile.js:198:41
    at Array.forEach (<anonymous>)
    at Object.compressToBuffer (C:\Users\mirko\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\adm-zip\zipFile.js:182:23)
    at Object.writeZip (C:\Users\mirko\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\adm-zip\adm-zip.js:454:
```32)
    at client.generateUploadUrl.then.then (C:\Users\mirko\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\@google-cloud\functions-emulator\src\cli\controller.js:168:13)
!  functions: Failed to emulate refresh

I tried to update cli tools,

npm install -g firebase-tools
C:\Users\mirko\AppData\Roaming\npm\firebase -> C:\Users\mirko\AppData\Roaming\npm\node_modules\firebase-tools\bin\firebase
+ [email protected]
added 1 package, removed 1 package and updated 5 packages in 81.135s

Then the situation is more wrong than before

$ firebase deploy --only functions
internal/modules/cjs/loader.js:596
    throw err;
    ^

Error: Cannot find module 'update-notifier'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Users\mirko\AppData\Roaming\npm\node_modules\firebase-tools\bin\firebase:5:22)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)

realtebo avatar Jun 16 '18 09:06 realtebo

Why firebase cli make us much trouble always? I'm tired of errors, switching to azure

ofarukcaki avatar Jul 02 '18 17:07 ofarukcaki

Try AWS too.

paritosh149 avatar Jul 03 '18 10:07 paritosh149

@realtebo have you tried the patch here? https://github.com/firebase/firebase-tools/issues/770#issuecomment-390622784

that fixed this node 10 error for me:

RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received 2413610064
    at checkInt (internal/buffer.js:35:11)
    at writeU_Int32LE (internal/buffer.js:515:3)
    at Buffer.writeInt32LE (internal/buffer.js:684:10)
    at Object.entryHeaderToBinary (/Users/alex/.config/yarn/global/node_modules/adm-zip/headers/entryHeader.js:216:18)

alexlouden avatar Jul 05 '18 08:07 alexlouden

@alexlouden : I'll try. If works, I'll try to open a PR into the related repo

realtebo avatar Jul 05 '18 08:07 realtebo

I had the same problem for a different reason than the one mentionned above.

In my case, I had a console running firebase serve, and trying to run firebase functions:shell in another one failed.

Killing the process of firebase serve and running firebase functions:shell solved the problem. It looks like both can't run at the same time.

I did try the workaround in https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/173#issuecomment-369001442 before, so it may or may not have changed something.

jberube avatar Jul 05 '18 15:07 jberube

@jberube : sorry, I don't understand.

"I did try the workaround in #173 (comment) before, so it may or may not have changed something."

You have already tried this workaround. But have you still the problem or is it fixed? "May or may not" ... is confusing me ...

realtebo avatar Jul 05 '18 17:07 realtebo

@google-admin : please, trash this dependency ! it's still using

  "engines": {
    "node": ">=0.3.0"
  }

realtebo avatar Jul 05 '18 18:07 realtebo

@realtebo I've updated my comment to be clearer.

Problem is solved for me. I'm not sure if deleting the ~/.config/configstore/@google-cloud folder was necessary in my case.

jberube avatar Jul 05 '18 20:07 jberube

Had same error. It appears that it was happening for me because I had another functions process running. After closing it I could run the other functions process fine

ilearnio avatar Jul 17 '18 22:07 ilearnio

I still have this issue locally, deploying to firebase cloud works fine(remote). Re-installed node 6.11.5, restarted function process had no effect. deleting google-cloud had no effect. (c:\users<your username.config\configstore@google-cloud)

i  functions: Preparing to emulate functions.
ERROR: Function load error: Code could not be loaded.
ERROR: Does the file exists? Is there a syntax error in your code?
ERROR: Detailed stack trace: module.js:471
    throw err;
    ^

What is causing this issue? Any suggestions, advises ? Thanks.

prakis avatar Jul 24 '18 12:07 prakis

I think after a day struggle it magically started working. I am not sure what really helped, I believe it is mostly related to reinstalling firebase functions and node versions.

I still have some minor issues like port locked.

error: restPort (5002) is already in use
error: SUPERVISOR error Error: listen EADDRINUSE 127.0.0.1:5001
    at Object.exports._errnoException (util.js:1020:11)
    at exports._exceptionWithHostPort (util.js:1043:20)
    at Server._listen2 (net.js:1262:14)
    at listen (net.js:1298:10)
    at net.js:1408:9
    at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:81:10)
error: supervisorPort (5001) is already in use

prakis avatar Jul 24 '18 14:07 prakis

@prakis look for other processes using the same ports (5001, 5002). I had this error in another context in the past because my console emulator would close but the node process was still running.

jberube avatar Jul 28 '18 23:07 jberube

Thats right @jberube, the previous node process is still running in the background and locking those ports. Thank you.

prakis avatar Jul 29 '18 07:07 prakis

Node 6.11.5 is the only version which is working for me. Strangely other firebase project works fine with latest node version.

prakis avatar Aug 12 '18 19:08 prakis

I tried many ways. The only one that worked was switching to node version 6.11.5

$ nvm use 6.11.5 Now using node v6.11.5 (npm v3.10.10) $ nvm alias defalt 6.11.5 defalt -> 6.11.5 (-> v6.11.5) $ node --version v6.11.5 $ npm run shell

functions@ shell /opt/dev/angular-firebase-projects/cloud-functions/cloud-functions-master-course/functions npm run build && firebase experimental:functions:shell

functions@ build /opt/dev/angular-firebase-projects/cloud-functions/cloud-functions-master-course/functions tsc

i functions: Preparing to emulate functions. ✔ functions: createUserRecord info: Worker for createUserRecord closed due to file changes. ✔ functions: basicHttp info: Worker for basicHttp closed due to file changes. ✔ functions: api firebase >

jesselima avatar Dec 07 '18 21:12 jesselima