Firebase: Cannot start emulator - firebase

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.

Solution is:
yarn global add firebase-tools
yarn global add #google-cloud/functions-emulator --ignore-engines

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!

The following worked for me.
npm uninstall -g firebase-tools && npm i -g firebase-tools
npm i --save #google-cloud/firestore
npm i --save #google-cloud/common-grpc
npm i -g #google-cloud/functions-emulator
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"
}

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.

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:
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
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
Install nvm (node version manager) by following the instructions here:
https://github.com/creationix/nvm#install-script
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
Install the Google Cloud Platform SDK:
https://cloud.google.com/sdk/
Reinstall the functions emulator:
npm install -g #google-cloud/functions-emulator
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

Related

Multiple Versions of Firebase Installed - Which Do I Use?

I'm trying to build an app with Firebase and ran a few commands to see which version I have. To follow along with a 2021 instruction video, I was hoping to have Firebase v9. Depending on the command that I run, I somehow have versions 8 and 11. If I have these two versions, which one is actually being used? What is the difference between seemingly having an npm firebase and non-npm firebase installed?
armadillo#armadillo-MacBook-Air my-app % npm firebase --version
8.11.0
armadillo#armadillo-MacBook-Air my-app % firebase -V
11.2.2
If you're trying to work with the Firebase CLI, you should be looking at the firebase-tools npm package, not firebase. They are definitely not the same thing.
npm firebase-tools --version
I suggest reviewing the documentation as well.
As covered by #Doug's answer, the firebase command is defined by the firebase-tools npm package (or by https://firebase.tools if installed that way) not the firebase package, which does not define any command line utilities.
Additionally, npm --version returns the version of npm you have installed. This includes if you add the name of a package there. (i.e. npm thisCouldBeAnythingNotANPMCommand --version will return the same result)
If you want to view the version of a deployed package, you would use one of the following commands to query NPM's database:
npm view firebase version (view package's "version" field)
npm v firebase version (view package's "version" field, using shorthand)
npm view firebase (get all available package information)
If you want to view the version of a package installed in your project or globally, you would use:
npm ls firebase (local install)
npm ls -g firebase-tools (global install)
If you want to view the where the npm-installed commands are, you would use:
npm bin (local install)
npm bin -g (global install)
For the firebase command, the firebase/firebase.cmd/firebase.ps1 files all point to <global bin directory>/node_modules/firebase-tools/lib/bin/firebase.js.
Compare the results of:
> npm v firebase version
9.9.0
> npm ls firebase
`-- firebase#9.0.0-beta.6 (an old project directory for another SO answer)
> npm v firebase-tools version
11.2.2
> npm ls -g firebase-tools
`-- firebase-tools#9.21.0 (updated since :D)
> npm --version
6.4.12
> npm firebase --version
6.4.12
> npm v npm version
8.14.0 (updated since :D)

Package.json indicates an outdated version of firebase-functions

I have Cloud functions project and i moved the project from my old laptop to my new laptop.
I have installed everything that necessary. My problem is when i try firebase deploy it gives me that error:
! functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions#latest in your functions directory.
I did that i have been told, but still it gives me the same error.
What should i do? And how i direct the npm install to my functions directory?
You need to run sudo npm install --save firebase-functions#latest in your functions directory. Cannot be in any other directory.
In Flutter this will be in
/path_to_your_flutter_project/functions
Hope this helped someone
I had the same problem.
You just need to run npm install -g firebase-tools
npm install -g firebase-tools
/usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/lib/bin/firebase.js
+ firebase-tools#7.0.0
That fixed my problem.
Update firebase-admin and make sure your root package.json file points to your functions folder

Install ghost blog meet `npm WARN cannot run in wd ghost`

while I download ghost ,and unzip it to new_ghost ,then i meet this error
➜ new_ghost npm install --production
npm WARN cannot run in wd ghost#0.11.2 node core/server/utils/npm/preinstall.js (wd=/var/www/new_ghost)
[1] 14831 killed npm install --production
If you look in package.json you will see the preinstall script. It is looking for node. If you are working on Ubuntu, you might need to change that to nodejs. Another thing to try is:
npm cache clean
rm -rf node_modules
npm install --production
npm start --production
Another possibility is if you are using a version of node that it doesn't support. In that case you can disable the version check:
GHOST_NODE_VERSION_CHECK=false npm install --production
GHOST_NODE_VERSION_CHECK=false npm start --production
I had the same problem.
As mentioned by the Ghost folks here http://support.ghost.org/troubleshooting/#npm-start-issues, you should enable or increase the swap size.
If you don't have swap enabled, you can follow the guide here: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-12-04

firebase version is not updating through <npm install -g firebase-tools>

i am windows user and trying to update firebase version using
npm install -g firebase-tools but when i run firebase --version
it shows the same version.
I also run npm uninstall firebase --save and check firebase --version it shows same.
what should i do to update my firebase version?
npm update -g firebase-tools
or
npm install -g firebase-tools#3.12.0 to install a specific version
And make sure to restart your terminal/IDE otherwise, it won't take effect.
Have you tried npm update -g firebase-tools? This worked for me.
These days if you're on an older version, and you check the version of firebase-tools, by running:
firebase -V
along with the version of firebase-tools that you're on, it also gives you a messages, something like this:
So you can basically run npm i -g firebase-tools to update the version of your firebase-tools installation to the latest version.
Hope this helps :)
For other like me stumbling in with a weird version mismatch:
When I did firebase -V in my terminal I would get a different version (5.1.1) than when I ran firebase through a npm run script (3.19.3)
The problem was that I had previously installed firebase locally into that project. In other words, I was getting the global version in the terminal, but npm was using the node_modules version
To confirm this, I added a simple test called test-foo to my package.json (firebase -V && which firebase) and ran it:
kuzyn(λ)matebox‡ npm run test-foo
kuzyn-project#1.1.0 test-foo /home/kuzyn/code/kuzyn-project/firebase
firebase -V && which firebase
3.19.3
/home/kuzyn/code/kuzyn-project/firebase/node_modules/.bin/firebase
Then I removed the (uneeded in my case) local firebase package from the package.json and from node_modules
Try the 2 steps bellow
1. yarn/npm cache clean
2. npm install -g firebase firebase-tools or yarn add -g firebase firebase-tools
in a new terminal, firebse --version
works for me
it works to me...
standalone binary: Download the new version, then replace it on your system
if you are using the standalone.Download the new version
In my case I was using an old node version (v10) and had to switch to a newer one (v12). After that I ran npm install -g firebase-tools again and it was updated to the latest version.
You can check the current node version by running node -v. And I use nvm to switch to a different node version.
That might happen in case you've installed the firebase-cli using a so called automatic install script.
Try to call curl -sL https://firebase.tools | upgrade=true bash as described in the official documentation

How to uninstall npm package?

I've installed grunt using sudo npm install grunt and now I can't remove it.
I've tried:
$ sudo npm uninstall grunt
But it gives me a WARN:
npm WARN uninstall not installed in /home/kuba/projects/node_modules: "grunt-cli"
I've also tried rm, remove and unlink. and -g options, but those give:
npm WARN uninstall not installed in /usr/lib/node_modules: "grunt"
But I still can run grunt from command line.
EDIT:
$ whereis grunt
grunt: /usr/local/bin/grunt
$ file /usr/local/bin/grunt
/usr/local/bin/grunt: symbolic link to `../lib/node_modules/grunt/bin/grunt'
$ ls /usr/local/lib/node_modules
grunt jshint
$ ls /usr/lib/node_modules
bower csslint devtools-terminal npm plato
Why I have 2 directories with npm? Is it safe to just delete them?
EDITOR NOTE:
This question was asked over 5 years ago as How to uninstall npm package. It's been a very useful question favourited by many, who found a solution to their problem, so I'm changing it back from a recent edit that called it How to uninstall grunt package, because it requires the same procedure as any other npm package.
To uninstall a npm module from project node_modules folder, run:
npm uninstall <module> --save
Note that npm modules should be uninstalled from the same directory that contains the node_modules folder when running this command. The --save option will also remove it from your package.json
One can also remove a local dependency/module installation, by deleting its directory from the local node_modules folder. Yes, it's safe to delete dependencies there.
To uninstall a npm module that was installed globally, run:
npm uninstall -g <module>
It doesn't matter where you run this command from.
To install a npm module, run: (only meant as reference)
npm install <module>
...or:
npm install (if there's a package.json file at the root of your project)
...or:
npm install <module> --save-dev (if you want to add a minimum version to the dependency)
Good things to know about Grunt:
If you have installed grunt stable before February 18, 2013 (the day grunt v0.4.x was released), you might have an older grunt version still lingering in your system. That's because grunt versions lower than 0.4.x were installed globally, which caused a lot of pain when upgrading/maintaining versions.
grunt and grunt-cli are two different things.
grunt (without the "cli") is usually installed at the project level (when listed as a devDependency in package.json) by running npm install. That's also known as a local installation.
grunt-cli is the underlying foundation on which local versions of grunt run in different projects/folders. It can be installed locally, but is more useful when installed globally, once.
grunt is only installed locally (by running npm install grunt).
grunt-cli is preferably installed globally (by running npm install -g grunt-cli). grunt-cli official npm page still warns against installing grunt (without the cli) globally.
If you want to uninstall the global installation of grunt-cli, run npm uninstall -g grunt-cli. This issue on gruntjs's project supports this procedure.
Never install grunt globally (by running npm install -g grunt).
On npm and sudo
sudo doesn't play well with npm. Only use it if you must. Below are two quotes on the advantages and disadvantages on its use:
Quoting Isaac Z. Schlueter on his Introduction to npm article:
I strongly encourage you not to do package management with sudo!
Packages can run arbitrary scripts, which makes sudoing a package manager command
as safe as a chainsaw haircut. Sure, it's fast and definitely going to cut
through any obstacles, but you might actually want that obstacle to stay there.
I recommend doing this once instead:
sudo chown -R $USER /usr/local
That sets your user account as the owner of the /usr/local directory, so that you can
just issue normal commands in there. Then you won't ever have to use sudo when you
install node or issue npm commands.
It's much better this way. /usr/local is supposed to be the stuff you installed, after all.
Yet another catch mentioned by Andrei Karpushonak:
There are certain security concerns and functionality limitations
regarding changing the ownership of /usr/local to the current user:
if there is another user on the machine who could use global
npm packages - do not change the ownership of /usr/local
https://apple.stackexchange.com/questions/1393/are-my-permissions-for-usr-local-correct
https://askubuntu.com/questions/261326/is-it-safe-to-chown-usr-local
Having said that, if you want to install global module without using sudo,
I don't see any better solution (from pragmatic point of view) than mentioned.
Security vs easy of use is very broad topic, and there is no easy answer for that
- it just depends on your requirements.
This same thing happened with me. On doing
which grunt
I got path /usr/local/bin/. There was a folder grunt inside this.
But on running command (even from within the path /usr/local/bin/):
sudo npm uninstall -g grunt
Got the warning uninstall not installed
Solution: turns out that I installed using command
sudo npm install -g grunt-cli
And while trying to remove was just typing grunt.
So once I run
sudo npm uninstall -g grunt-cli
grunt got removed.
Although you have mention in question that you run
sudo npm install grunt
But still check if you are also doing the same mistake and run it with grunt-cli.
In some cases it may be necessary to use npm's "remove a package," feature.
npm - Remove a package
Description
"This uninstalls a package, completely removing everything npm installed on its behalf."
On your third code block, you posted this message:
npm WARN uninstall not installed in /home/kuba/projects/node_modules: "grunt-cli"
I've found that using the
which grunt
or the
whereis grunt
commands in the CLI/console provides an incomplete and confusing output.
Both of these commands will return the path of the grunt-cli installation, but return this simply as grunt.
Also using,
which grunt-cli
or the
whereis grunt-cli
fails to return any output to the CLI console. I believe that this is a namespace issue/feature with npm.
I also had a situation where I was unable to uninstall the grunt-cli with npm's uninstall function as recommended by other contributors above.
The only thing that worked for me was using the npm remove function with the program's full name as demonstrated below.
npm rm -g grunt-cli
This should return the following to your console.
unbuild grunt-cli##.##.#
Good Luck!
Use first this one
which grunt-cli
Or
which grunt
And this will show you the path to the module
In my case it was in the /usr/local/bin/
Once I got into the bin folder I just wrote
sudo rm grunt
And that was the end of it :)
If it's installed globally add -g to uninstall and probably you will need sudo
sudo npm uninstall -g grunt
Running the accepted solution's commands didn't work for me. Running which grunt would result in /usr/local/bin/grunt, but normal (or sudo) npm uninstall -g grunt-cli had no effect.
This is the command that finally worked for me:
sudo npm uninstall grunt-cli -g --prefix=/usr/local
Thanks to gengxuelei on github for the solution!

Resources