firebase / functions-samples

Collection of sample apps showcasing popular use cases using Cloud Functions for Firebase
https://firebase.google.com/docs/functions
Apache License 2.0
12.03k stars 3.83k forks source link

functions: Cannot start emulator #267

Closed jaycreate closed 6 years ago

jaycreate commented 6 years ago

Hi there, Refer to issue #200 I try reinstall grpc but still getting same error

After install grpc it show success but grpc_node.node is installed via remote, like this [grpc] Success: "/usr/local/lib/node_modules/grpc/src/node/extension_binary/node-v48-darwin-x64/grpc_node.node" is installed via remote

When run firebase deploy --only functions it it showing functions: Cannot start emulator. Error: Cannot find module '/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/grpc_node.node'

I checked in directory was nothing inside /usr/local/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary

Please give some advice, thank you in advance.

ioemcmmproject commented 6 years ago

Similar issue - I've found various other threads on here related to this, but none of them seem to work. For me, somehow not only am I getting the above error: Cannot start emulator. Error: Cannot find module '/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/grpc_node.node'

But for me when I use "sudo npm install -g grpc" I get the following error:

node-pre-gyp ERR! Tried to download(undefined): https://storage.googleapis.com/grpc-precompiled-binaries/node/grpc/v1.7.0/node-v57-darwin-x64.tar.gz node-pre-gyp ERR! Pre-built binaries not found for grpc@1.7.0 and node@8.9.0 (node-v57 ABI) (falling back to source compile with node-gyp) gyp WARN EACCES user "root" does not have permission to access the dev dir "/Users/michaelrhanscom/.node-gyp/8.9.0" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/grpc/.node-gyp"

Where the last 2 gyp warnings continue to populate on the screen over and over until I terminate the process. I tried to use "sudo npm install -g grpc --allow-root --unsafe" which seemed to work, but when I go back through the various folders, I still get down to '/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/src/node" and then beyond that the folder for "extension_binary" doesn't even exist. Additionally, for the path within the above error, within the node_modules/grpc, the folder .node_gyp also doesn't exist. Help?

darwinyip commented 6 years ago

I was able to install it using yarn instead. sudo yarn add firebase-tools

vik17ag commented 6 years ago

Hi,

I am facing this error in windows. When i type firebase experimental:functions:shell , i get this error - ! functions: Cannot start emulator. Error: Cannot find module '@google-cloud/functions-emulator/src/confi g' I am able to run the function on server when i deploy . Please help, thanks

inlined commented 6 years ago

Everyone who is using sudo in your install scripts: this is not the recommended best practice

Consider fixing NPM permissions

@vik17ag The emulator is an optional dependency of firebase-tools (since only Cloud Functions needs that high a version of Node). I'd try the following:

  1. Reinstall firebase-tools to make sure you have the latest version with npm install -g firebase-tools
  2. If it still doesn't work, see whether you get more detailed error messages when installing the emulator with npm install -g @google-cloud/functions-emulator
inlined commented 6 years ago

Also, as a side comment to others: grpc is a native node binary. Native binaries often only work with the version of Node for which they were compiled. If you are using nvm please make sure you've installed grpc on the same version of Node.

vik17ag commented 6 years ago

Thanks for reply. I tried reinstalling firebase tools & install emulator as mentioned by you but got the below log error

$ npm install -g @google-cloud/functions-emulator C:\Users\vivek-pc\AppData\Roaming\npm\functions-emulator -> C:\Users\vivek-pc\AppData\Roaming\npm\node_modules\@google-cloud\functions-emulator\bin\functions npm ERR! path C:\Users\vivek-pc\AppData\Roaming\npm\functions npm ERR! code EISDIR npm ERR! errno -4068 npm ERR! syscall open npm ERR! EISDIR: illegal operation on a directory, open 'C:\Users\vivek-pc\AppData\Roaming\npm\functions'

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\vivek-pc\AppData\Roaming\npm-cache_logs\2017-11-22T05_53_40_280Z-debug.log

inlined commented 6 years ago

Interesting. I wonder if there's a problem with an old version of the library. Mind copying the state from that debug log so I can see what was happening when NPM tried to treat that directory like a file?

viggy28 commented 6 years ago

@inlined I have a similar issue. functions vignesh.ravichandran$ firebase experimental:functions:shell ⚠ functions: Cannot start emulator. Error: Cannot find module '/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/node-v57-darwin-x64/grpc_node.node'

When i looked for the file, i found a directory node-v48-darwin-x64 under extension_binary. It looks like version mismatch. Any advice? Thanks.

vguhesan commented 6 years ago

I had the same issue when I ran on my Mac OS X High Sierra (not clear if this happens on Windows or Linux platforms)

sudo npm install -g firebase-tools

Error/Warning:

gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.9.1" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"

Here is what I did to avoid this: sudo mkdir -p /usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.9.1/

This creates an empty directory with the path specified then rerun the following: sudo npm install -g firebase-tools

I hope this helps.

MyThinkPond | vguhesan

inlined commented 6 years ago

@vguhesan You're continuing to dig yourself into the "sudo" rabbit hole, which is a bit dangerous. Any exploit of a Node tool on your system could lead to a full compromise of your development machine. See my linked instructions above for fixing node permissions.

@vr001 The v48 and v57 are likely referring to different V8 engines. I'd run npm uninstall -g grpc, use nvm to switch to the Node version you want, and run npm install -g grpc. I'm honestly not sure if the npm uninstall command needs to be run with nvm set to the newer version of Node.

@vik17ag Still waiting on your response specifically. The contents of C:\Users\vivek-pc\AppData\Roaming\npm-cache_logs\2017-11-22T05_53_40_280Z-debug.log would help me understand why there was a directory that the installer expected to be a file.

vik17ag commented 6 years ago

Hi, Sorry for delay. Log file attached. 2017-11-28T06_10_07_979Z-debug.log

jaycreate commented 6 years ago

Last week I try make ln link to the location that grpc installed, it work. /usr/local/lib/node_modules/grpc/src/node/extension_binary/node-v48-darwin-x64/grpc_node.node

hope this help.

inlined commented 6 years ago

@vik17ag From your debug logs it looks like this is at the final step where node "binaries" are created (by linking them back to their real scripts). I might guess that a code structure change of @google-cloud/functions-emulator previously linked against a directory and now it links against a file.

I would first try:

npm uninstall -g @google-cloud/functions-emulator
dir C:\Users\vivek-pc\AppData\Roaming\npm\functions

If the dir command shows that "functions" no longer exists, then you should be able to successfully run npm install -g @google-cloud/functions-emulator If the directory did still exist after you uninstalled your old version of the emulator, we'll need to look into that directory and try to guess what node module has a conflicting name.

vik17ag commented 6 years ago

I ran the uninstall command, but function directory exists and has following structure 04/15/2017 12:17 PM

. 04/15/2017 12:17 PM .. 04/15/2017 12:16 PM 301 index.js 04/15/2017 12:17 PM node_modules 04/15/2017 12:16 PM 184 package.json 2 File(s) 485 bytes 3 Dir(s) 11,754,094,592 bytes free The node_module directory has following directories - 04/15/2017 12:17 PM . 04/15/2017 12:17 PM .. 04/15/2017 12:17 PM .bin 04/15/2017 12:17 PM @types 04/15/2017 12:17 PM accepts 04/15/2017 12:17 PM array-flatten 04/15/2017 12:17 PM base64url 04/15/2017 12:17 PM buffer-equal-constant-time 04/15/2017 12:17 PM charenc 04/15/2017 12:17 PM content-disposition 04/15/2017 12:17 PM content-type 04/15/2017 12:17 PM cookie 04/15/2017 12:17 PM cookie-signature 04/15/2017 12:17 PM crypt 04/15/2017 12:17 PM debug 04/15/2017 12:17 PM depd 04/15/2017 12:17 PM destroy 04/15/2017 12:17 PM ecdsa-sig-formatter 04/15/2017 12:17 PM ee-first 04/15/2017 12:17 PM encodeurl 04/15/2017 12:17 PM escape-html 04/15/2017 12:17 PM etag 04/15/2017 12:17 PM express 04/15/2017 12:17 PM finalhandler 04/15/2017 12:17 PM firebase-admin 04/15/2017 12:17 PM firebase-functions 04/15/2017 12:17 PM forwarded 04/15/2017 12:17 PM fresh 04/15/2017 12:17 PM hoek 04/15/2017 12:17 PM http-errors 04/15/2017 12:17 PM inherits 04/15/2017 12:17 PM ipaddr.js 04/15/2017 12:17 PM isemail 04/15/2017 12:17 PM joi 04/15/2017 12:17 PM jsonwebtoken 04/15/2017 12:17 PM jwa 04/15/2017 12:17 PM jws 04/15/2017 12:17 PM lodash 04/15/2017 12:17 PM lodash.once 04/15/2017 12:17 PM media-typer 04/15/2017 12:17 PM merge-descriptors 04/15/2017 12:17 PM methods 04/15/2017 12:17 PM mime 04/15/2017 12:17 PM mime-db 04/15/2017 12:17 PM mime-types 04/15/2017 12:17 PM moment 04/15/2017 12:17 PM ms 04/15/2017 12:17 PM negotiator 04/15/2017 12:17 PM on-finished 04/15/2017 12:17 PM parseurl 04/15/2017 12:17 PM path-to-regexp 04/15/2017 12:17 PM proxy-addr 04/15/2017 12:17 PM qs 04/15/2017 12:17 PM range-parser 04/15/2017 12:17 PM safe-buffer 04/15/2017 12:17 PM send 04/15/2017 12:17 PM serve-static 04/15/2017 12:17 PM setprototypeof 04/15/2017 12:17 PM sha1 04/15/2017 12:17 PM statuses 04/15/2017 12:17 PM topo 04/15/2017 12:17 PM type-is 04/15/2017 12:17 PM unpipe 04/15/2017 12:17 PM utils-merge 04/15/2017 12:17 PM vary 04/15/2017 12:17 PM xtend 0 File(s) 0 bytes 66 Dir(s) 11,782,848,512 bytes free

Can i try uninstalling npm or firebase -tools and re-installing them?

inlined commented 6 years ago

LOL. I think I would bet $1 that you initialized a firebase project in C:\Users\vivek-pc\AppData\Roaming\npm.

What is the contents of C:\Users\vivek-pc\AppData\Roaming\npm\package.json?

vik17ag commented 6 years ago

Oh Gosh, I think i did.

package.json contents -

{ "name": "functions", "description": "Cloud Functions for Firebase", "dependencies": { "firebase-admin": "~4.1.2", "firebase-functions": "^0.5" }, "private": true }

Pls suggest what do i do?

inlined commented 6 years ago

It's totally fine to just delete the directory. You probably also have an extra "firebase.json" and ".firebaserc" one level higher. You might have other junk sibling directories like "public" that are a default Firebase Hosting directory.

marckrenn commented 6 years ago

This fixed it for me: https://github.com/firebase/firebase-admin-node/issues/121#issuecomment-339453329

elihorne commented 6 years ago

I have this same issue. I've followed various steps referenced in this thread, but cannot get the emulator to start.

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'

inlined commented 6 years ago

@elihorne Please try running npm install -g grpc. If that fails to install you should have your answer.

marckrenn commented 6 years ago

@elihorne I think I fixed the issue described in your post by deleting the node_modules folder followed by running npm install.

amitava82 commented 6 years ago

Same problem here. installed npm install -g grpc without error

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

grantkemp commented 6 years ago

I get this error :


node-pre-gyp ERR! Tried to download(403): https://storage.googleapis.com/grpc-precompiled-binaries/node/grpc/v1.6.6/node-v59-darwin-x64.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for grpc@1.6.6 and node@9.3.0 (node-v59 ABI) (falling back to source compile with node-gyp) 

Has google removed the old version.. https://storage.googleapis.com/grpc-precompiled-binaries/node/grpc/v1.6.6/node-v59-darwin-x64.tar.gz - looks like its giving a 403 error?

AccessDenied Access denied.
Anonymous users does not have storage.objects.get access to grpc-precompiled-binaries/node/grpc/v1.6.6/node-v59-darwin-x64.tar.gz.
lufonius commented 6 years ago

I also had this problem, but i could fix it. The error looked like the following: functions: Cannot start emulator. Error: Cannot find module '/usr/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-glibc/grpc_node.node'

so i looked up which version corresponds to 'node-v57':
Node Versions

I installed the corresponding version with nvm nvm install 8.9.3

then i uninstalled the firebase-tools global package and installed it again (yes, sudo, i know ....):

sudo npm uninstall -g firebase-tools

sudo npm --unsafe-perm install -g firebase-tools 

I used the --unsafe-perm flag, because when not doing so it ended in an endless loop of the following error message (but i actually don't know what the flag exactly is for, but it's needed, otherwise the emulator wouldn't start):

gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"  
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.9.3"

After these commands the emulator was able to start. My guess is that this error occurs when firebase-tools (or the functions-emulator) are installed with the "wrong" node version.

Maybe this helps someone.

bjornharvold commented 6 years ago

Having the same issue. Did not try to replicate using @lufonius work around.

katherdx commented 6 years ago

Facing same issue: ! functions: Cannot start emulator. Error: Cannot find module\c:\user\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\grpc\src\node\extension_binary\node-v57-win32-x64-unknown\grpc_node.node'

jmdobry commented 6 years ago

If you need to use sudo to run any node or npm commands, if you have needed to use sudo in the past for any node or npm command, or if you needed to use sudo to install Node.js and npm, then this could indicate a problem with your Node.js installation.

To remedy:

  1. Completely wipe any trace of Node.js (including any modules installed via npm) from your system.

  2. Reinstall Node.js using nvm (or nvm-windows).

  3. Install your desired version of Node.js. If you're using the Emulator, install v6.11.5

    nvm install v6.11.5
    nvm alias default v6.11.5
    nvm use v6.11.5
    npm install -g npm
  4. Now you may install Firebase tools (and the emulator), after switching to the right version of Node.js.

    npm install -g firebase-tools

If you get any module version mismatch errors, it's because you installed an npm module with native dependencies (in this case, the emulator) with one version of Node.js, and then you tried to run it with a different version of Node. It has to be installed and run with the same version of Node.js. Uninstall and reinstall with the right version of Node.js.

If you're still having problems installing grpc, please open an issue on the grpc repo with details of your system environment.

merlinnot commented 6 years ago

@jmdobry is right af. This really works when it’s configured correctly. You can try it out in a vm or a Docker container to see for yourself on a clean system. I’ve made it work in my dev environment without a hassle, see this file to see how the Node is being installed in this container.

There’s also a little gotcha in @jmdobry ‘s solution: yarn is not managed by nvm. It might interfere with nvm in many, many ways.

katherdx commented 6 years ago

I just reinstall npm install -g firebase-tools. Now its working.. Step 1: npm uninstall -g firebase-tools Step 2: npm install -g firebase-tools

shawndewet commented 6 years ago

Running Windows 10, admin command prompt, I'm running "firebase init" and it is failing with the following output:

? Do you want to install dependencies with npm now? Yes ...other output here...and then the following failure... grpc@1.6.6 install C:\Development\fbTools\functions\node_modules\firebase-admin\node_modules\grpc node-pre-gyp install --fallback-to-build --library=static_library

node-pre-gyp ERR! Tried to download(403): https://storage.googleapis.com/grpc-precompiled-binaries/node/grpc/v1.6.6/node-v59-win32-x64.tar.gz node-pre-gyp ERR! Pre-built binaries not found for grpc@1.6.6 and node@9.3.0 (node-v59 ABI) (falling back to source compile with node-gyp)

And then the compile fails because I don't have all the build tools installed. But I don't want to have to compile from source code...why is the fetch of the pre-built binaries failing?

This is after having tried to resolve the problem re-installing firebase-tools as indicated by @katherdx

heardMan commented 6 years ago

This worked pretty well for me the error I was getting was:

gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"

So based on the link below I added npx to the end of the command and then the install worked.

https://www.npmjs.com/package/npx

sudo npm install -g firebase-tools npx

Shashaness commented 6 years ago

OS X 10.12.x

sudo rm -rf /usr/local/lib/node_modules Install Stable Node.js from https://nodejs.org/dist/v8.9.4/node-v8.9.4.pkg sudo npm install --unsafe-perm -g firebase-tools firebase init <setup a new firebase deployment with functions and hosting) firebase serve --only functions,hosting The key for me was to completely delete node_modules directory from /usr/local/lib, and reinstall firebase-tools using the --unsafe-perm command line option. No other suggestion worked.

Hope this helps.

inlined commented 6 years ago

Please do not recommend using sudo and --unsafe-perm. This would allow a malicious node module to compromise your whole machine

Shashaness commented 6 years ago

I would agree that you should not use --unsafe-perm in a production environment but to get things going on a dev box it's more than acceptable. I need to be able to develop the product, I can worry about hardening my prod environment when it comes to actually deployment.

shaji-Dev commented 5 years ago

This is what I get, anyone solved this issue?

functions: Cannot start emulator. Error: Cannot find module './acceleratedmobilepageurl/v1'
(node:16724) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'exit' of undefined
    at C:\....\node_modules\firebase-tools\lib\command.js:82:34
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:16724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rej
ection id: 2)
(node:16724) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.