Edison D'souza
Edison D'souza

Reputation: 4640

Firebase: Cannot start emulator

functions: Cannot start emulator. Error: Cannot find module '@google-cloud/functions-emulator/src/config'

This is the error message I get when I try to run functions locally on Mac. My Firebase version is 3.16.0. I tried doing sudo npm install -g @google-cloud/functions-emulator as well. But still no use. Please help.

Upvotes: 10

Views: 8493

Answers (5)

Daniel Garmoshka
Daniel Garmoshka

Reputation: 6354

Solution is:

yarn global add firebase-tools
yarn global add @google-cloud/functions-emulator --ignore-engines

Upvotes: 15

dmcquiggin
dmcquiggin

Reputation: 3379

I had the same problem, using Ubuntu 17.10.

Note: You do not need to, and should not, use sudo for the installation.

I resolved this by performing the following:

  1. Uninstall any previously attempted installed of the functions emulator.

    npm uninstall -g @google-cloud/functions-emulator
    

    and to make sure:

    yarn global remove @google-cloud/functions-emulator
    
  2. Delete all files in ~/.config/configstore/@google-cloud/functions-emulator. Note that there are some hidden files in this directory.

    rm -rf ~/.config/configstore/@google-cloud/functions-emulator
    
  3. Install nvm (node version manager) by following the instructions here:

    https://github.com/creationix/nvm#install-script

  4. Use nvm to install a specific version of node - at the time of writing, the Google Cloud Function Emulator (version 1.0.0-alpha.29) specifically requires 6.11.5.

    nvm install 6.11.5
    
  5. Install the Google Cloud Platform SDK:

    https://cloud.google.com/sdk/

  6. Reinstall the functions emulator:

    npm install -g @google-cloud/functions-emulator
    
  7. Start the emulator to verify installation has succeeded:

    functions start
    

IMPORTANT: Subsequently, when attempting to create a function that can be tested locally or deployed to Google Cloud, you should use the firebase init functions command within your project, and allow this to install dependencies via npm. A walkthrough of creating a test function with Firebase can be found here:

https://firebase.google.com/docs/functions/get-started

Upvotes: 0

Edison D'souza
Edison D'souza

Reputation: 4640

Working Solution!(OSX) None of the above worked for me. After a long struggle, I found the following solution.

cd my_project/functions

npm install @google-cloud/functions-emulator

Copy @google-cloud/functions-emulator folder generated inside node_modules.

cd /usr/local/lib/node_modules/@google-cloud && open .

Paste the functions-emulator folder here.

In your project's root directory, copy package.json inside functions/node_modules/@google-cloud/functions-emulator

cd /usr/local/lib && open .

Paste the package.json here.

npm install

Hurray! You are good to go. Now go back to your project's root directory and run.

sudo firebase serve --only hosting,functions

And the emulator should start normally.

Note: Do not run sudo npm install -g @google-cloud/functions-emulator since the files will be removed and reinstalled. This is where the installation fails and emulator fails to run.

Hope this helps!

Upvotes: 9

Kevin Koelzer
Kevin Koelzer

Reputation: 29

The following worked for me.

  1. npm uninstall -g firebase-tools && npm i -g firebase-tools
  2. npm i --save @google-cloud/firestore
  3. npm i --save @google-cloud/common-grpc
  4. npm i -g @google-cloud/functions-emulator
  5. npm i --save firebase-functions

current package.json snippet

"dependencies": {
    "@google-cloud/common-grpc": "^0.5.3",
    "@google-cloud/firestore": "^0.11.1",
    "firebase-functions": "^0.8.1",
    "firebase-admin": "5.8.1" 
}

Upvotes: 2

alainbex
alainbex

Reputation: 396

My system: Ubuntu 16.04.3

I had the same problem and the reason is that "@google-cloud/functions-emulator" is not installed in the 'npm global packages folder'.

In my case it happened because I installed firebase-tools globally using yarn, and I used it because when installing firebase-tools globally using npm I was getting an folder access error, which did not happen with yarn.

What I did to solve the problem was to follow these simple instruction from npm website to use a different folder for npm global packages (https://docs.npmjs.com/getting-started/fixing-npm-permissions).

Then I installed again with 'npm install -g firebase-tools' (without sudo) and it worked perfectly.

Upvotes: 0

Related Questions