Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

Can't serve firebase-functions locally #173

Open
Kar1Huang opened this issue Dec 15, 2017 · 34 comments
Open

Can't serve firebase-functions locally #173

Kar1Huang opened this issue Dec 15, 2017 · 34 comments

Comments

@Kar1Huang
Copy link

macOS@10.12.4
firebase-tools@3.16.0
firebase-admin@5.4.3
firebase-functions@0.7.3
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

@craigvl
Copy link

craigvl commented Dec 19, 2017

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.

@flado
Copy link

flado commented Jan 5, 2018

same issue here:

Win7 Ent x64

firebase-tools@3.16.0
"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
Copy link

flado commented Jan 5, 2018

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

! functions: Failed to emulate hello

@pamartineza
Copy link

Similar issue in a fresh project

macOS@10.13.2
firebase-tools@3.17.1
firebase-admin@5.8.1
firebase-functions@0.8.1
node@6.11.3

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

@craigvl
Copy link

craigvl commented Jan 20, 2018

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.

@wooliet
Copy link

wooliet commented Jan 20, 2018

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

@pamartineza
Copy link

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

@foush
Copy link

foush commented Jan 26, 2018

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

@shaunc869
Copy link

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

shaunc869 commented Feb 28, 2018

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.

@jeffreywescott
Copy link

Thanks @shaunc869 -- fixed my issue.

@abraham
Copy link

abraham commented May 16, 2018

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

@paritosh149
Copy link

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

@realtebo
Copy link

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

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

@realtebo
Copy link

realtebo commented Jun 16, 2018

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
+ firebase-tools@3.18.6
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)

@ofarukcaki
Copy link

ofarukcaki commented Jul 2, 2018

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

@paritosh149
Copy link

Try AWS too.

@alexlouden
Copy link

@realtebo have you tried the patch here? firebase/firebase-tools#770 (comment)

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)

@realtebo
Copy link

realtebo commented Jul 5, 2018

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

@jberube
Copy link

jberube commented Jul 5, 2018

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 #173 (comment) before, so it may or may not have changed something.

@realtebo
Copy link

realtebo commented Jul 5, 2018

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

realtebo commented Jul 5, 2018

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

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

@jberube
Copy link

jberube commented Jul 5, 2018

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

@ilearnio
Copy link

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

@prakis
Copy link

prakis commented Jul 24, 2018

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

prakis commented Jul 24, 2018

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

@jberube
Copy link

jberube commented Jul 28, 2018

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

@prakis
Copy link

prakis commented Jul 29, 2018

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

@prakis
Copy link

prakis commented Aug 12, 2018

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

@jesselima
Copy link

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 >

@santospandey
Copy link

I have added sudo before command and then works fine

@benwinding
Copy link

For anyone encountering this issue (including future me):

Error:

Waiting for operation to finish...done.
Deploying function.........failed.
ERROR: Function worker crashed with exit code: 1
undefinedWarning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may failfs.js:1384
    throw error;
    ^

Solution

  1. functions stop
  2. firebase login
  3. firebase use PROJECT_ID
  4. firebase serve --only functions

Now functions should work, as somehow this refreshes the authentication... I think

  1. functions config set projectId PROJECT_ID
  2. functions deploy

when this inevitably happens again, I'll update this comment.

@bbmk
Copy link

bbmk commented Apr 9, 2019

use sudo before serve !

@ryanmtaylor
Copy link

I deleted the files inside of ~/.config/configstore/@google-cloud/functions-emulator (careful finding that directory because of the @ symbol) and then ran it again and everything worked fine

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

No branches or pull requests