This is a proposed documentation improvement
I would submit this as a PR to the wiki "detailed installation instructions" docs, but I can't see a way of editing a wiki page.
When attempting to use the @google-cloud/functions-emulator with firebase-tools on a system using nvm which also has multiple version of node, so far as I can tell, you should use npm and not yarn to both install @google-cloud/functions-emulator globally as well as install firebase-tools globally.
I think this is because nvm segregates npm global installs by node version, while yarn global installs are shared between all node versions. Thus, if you install multiple packages globally via yarn which require different, incompatible versions of node, you're going to run into an error.
As an example, when using nvm in an Angular v7 monorepo which contains a project representing firebase cloud functions, the firebase functions package.json will require node v6.x while the rest of the repo will require node v8.x. If you install v7 of @angular/cli globally via yarn, it will require you to be using node >8.x. If you switch to node v6.x using nvm use and attempt to then install @google-cloud/functions-emulator globally, yarn will throw an error because angular/cli does not work with node v6 (and yarn shares global packages between node versions--or, probably more accurately, nvm doesn't seem to segregate yarn global packages like it does npm ones.).
Additionally, when emulating firebase cloud functions using @google-cloud/functions-emulator and firebase functions:shell, the firebase-tools global install expects the @google-cloud/functions-emulator global install to be installed using the same package manager (i.e. both firebase-tools and @google-cloud/functions-emulator seem to need to be installed globally using the same package manager, either both npm or both yarn).
- For example: if you do
yarn global add firebase-tools
nvm use v6.16.0
npm install -g @google-cloud/functions-emulator
firebase functions:shell
an error will be thrown. But everything works fine if both firebase-tools and @google-cloud/functions-emulator are installed using npm.
So, in conclusion, to use @google-cloud/functions-emulator with nvm, users should first run yarn global remove @google-cloud/functions-emulator firebase-tools and instead use nvm use to switch to the desired version of node and then run npm install -g @google-cloud/functions-emulator firebase-tools (if using node v6.x) or just npm install -g firebase-tools if using another version of node. As a reminder, users will need to reinstall firebase-tools globally for each version of node they have on their system.
I'm guessing angular + yarn + firebase is a common enough combo that it would be worthwhile to add a comment linking to more information in the readme.
This is a proposed documentation improvement
I would submit this as a PR to the wiki "detailed installation instructions" docs, but I can't see a way of editing a wiki page.
When attempting to use the
@google-cloud/functions-emulatorwithfirebase-toolson a system usingnvmwhich also has multiple version of node, so far as I can tell, you should usenpmand notyarnto both install@google-cloud/functions-emulatorglobally as well as installfirebase-toolsglobally.I think this is because
nvmsegregates npm global installs by node version, whileyarnglobal installs are shared between all node versions. Thus, if you install multiple packages globally via yarn which require different, incompatible versions of node, you're going to run into an error.As an example, when using nvm in an Angular v7 monorepo which contains a project representing firebase cloud functions, the firebase functions package.json will require node v6.x while the rest of the repo will require node v8.x. If you install v7 of
@angular/cliglobally via yarn, it will require you to be using node >8.x. If you switch to node v6.x usingnvm useand attempt to then install@google-cloud/functions-emulatorglobally, yarn will throw an error becauseangular/clidoes not work with node v6 (and yarn shares global packages between node versions--or, probably more accurately, nvm doesn't seem to segregate yarn global packages like it does npm ones.).Additionally, when emulating firebase cloud functions using
@google-cloud/functions-emulatorandfirebase functions:shell, the firebase-tools global install expects the@google-cloud/functions-emulatorglobal install to be installed using the same package manager (i.e. bothfirebase-toolsand@google-cloud/functions-emulatorseem to need to be installed globally using the same package manager, either bothnpmor bothyarn).firebase-toolsand@google-cloud/functions-emulatorare installed usingnpm.So, in conclusion, to use
@google-cloud/functions-emulatorwithnvm, users should first runyarn global remove @google-cloud/functions-emulator firebase-toolsand instead usenvm useto switch to the desired version of node and then runnpm install -g @google-cloud/functions-emulator firebase-tools(if using node v6.x) or justnpm install -g firebase-toolsif using another version of node. As a reminder, users will need to reinstallfirebase-toolsglobally for each version of node they have on their system.I'm guessing angular + yarn + firebase is a common enough combo that it would be worthwhile to add a comment linking to more information in the readme.