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!