googlearchive / cloud-functions-emulator

A local emulator for deploying, running, and debugging Google Cloud Functions.
https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki
Apache License 2.0
827 stars 115 forks source link

Can't serve firebase-functions locally #173

Open Kar1Huang opened 6 years ago

Kar1Huang commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

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 commented 6 years ago

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

pamartineza commented 6 years ago

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 commented 6 years ago

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

shaunc869 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Thanks @shaunc869 -- fixed my issue.

abraham commented 6 years ago

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

paritosh149 commented 6 years ago

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

realtebo commented 6 years ago

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

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

realtebo commented 6 years ago

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 commented 6 years ago

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

paritosh149 commented 6 years ago

Try AWS too.

alexlouden commented 6 years ago

@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)
realtebo commented 6 years ago

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

jberube commented 6 years ago

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.

realtebo commented 6 years ago

@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 commented 6 years ago

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

  "engines": {
    "node": ">=0.3.0"
  }
jberube commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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

prakis commented 6 years ago

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

jesselima commented 5 years ago

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 commented 5 years ago

I have added sudo before command and then works fine

benwinding commented 5 years ago

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 commented 5 years ago

use sudo before serve !

ryanmtaylor commented 5 years ago

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