I am unable to deploy my cloud function. It is reporting I have a missign dependency loglevel although it is listed in my package.json file
firebase: 6.1.2
node js: 8.10.0
OSX Mojave
% npm run deploy
> functions@ deploy /Users/quoc/dev/projects/live-scores/src/google-action/functions
> firebase deploy --only functions
npm http request GET https://registry.npmjs.com/firebase-functions
npm http 200 https://registry.npmjs.com/firebase-functions
=== Deploying to 'sports-genie'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint /Users/quoc/dev/projects/live-scores/src/google-action/functions
> eslint .
✔ functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (69.35 KB) for uploading
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 8 function gameScore(us-central1)...
âš functions[gameScore(us-central1)]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'loglevel'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/index.js:5:13)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
Functions deploy had errors with the following functions:
gameScore
To try redeploying those functions, run:
firebase deploy --only functions:gameScore
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ deploy: `firebase deploy --only functions`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/quoc/.npm/_logs/2018-12-09T21_05_06_548Z-debug.log
package.json
{
"name": "functions",
"engines": {
"node": "8"
},
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "NODE_ENV=test mocha"
},
"dependencies": {
"@google-cloud/firestore": "^0.19.0",
"actions-on-google": "^2.5.0",
"axios": "^0.18.0",
"cheerio": "^1.0.0-rc.2",
"firebase-admin": "~6.0.0",
"firebase-functions": "^2.1.0",
"lodash": "^4.17.11",
"loglevel": "^1.6.0",
"moment": "^2.22.2"
},
"devDependencies": {
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0",
"mocha": "^5.2.0",
"rewire": "^4.0.1",
"should": "^13.2.3",
"sinon": "^7.1.1"
},
"private": true
}
Deployment going thru
Deployment stoped at last step
Hmm, nothing is sticking out to me as an issue from what you've described. I would check the following:
1 - functions/package.json has loglevel (which is seems so, but triple check)
2 - run an npm install in the functions directory
3 - run firebase deploy --only functions from the parent directory of functions.
It's a little difficult to debug this via issues, but we can try. You can also reach out on the Slack Channel for more real-time help from the community.
@bkendall Thanks for looking into this. The next day, I checked out my repo on another machine and was able to deploy. I just went back to the same machine I originally experienced the problem and it went thru as well.
Could it be an intermittent problem on your end as explained at https://status.firebase.google.com/incident/Functions/17024?
Hard to say without more detailed logs and debugging information. Glad it's back working for you.
Solved this problem. Searched it everywhere got no solution.
Follow these steps.
Updating firebase tools did the trick for me:
npm install -g firebase-tools
This can happen when you "npm install" a dependency to the wrong folder, as I have just realised I did. I have a Vue project in the "src" subdirectory, and an index.js (Firebase cloud function) in the "functions" subdirectory.
Dependencies of the Vue project must be installed with "npm install" in the main directory. In contrast, dependencies of the Firebase cloud function must be installed with "npm install" being run in the "functions" subdirectory. I had accidentally installed the dependency in the main directory, and was breaking my head trying to understand why it was complaining that it couldn't find the dependency (googleapis) until I realised what I had done. The fix was of course to install it in the right place (so it showed up in the right package.json), and uninstall it from the wrong place for neatness.
I faced a similar error and realised my 'lodash.clonedeep' dependency was somehow under devDependencies instead of dependencies, causing firebase to complain it couldn't find the dependency. Moving it to dependencies worked out for me.
Thanks @darrelfrancis!, I had the same issue.
I installed the sendgrid package in the higher order config file src/package.json, when I should've installed it on src/functions/package.json.
One thing that may help others is changing the "engines":{"node"} from 10 to 8... for some reason it display a better log error that node 10 ¯_(ツ)_/¯
Most helpful comment
This can happen when you "npm install" a dependency to the wrong folder, as I have just realised I did. I have a Vue project in the "src" subdirectory, and an index.js (Firebase cloud function) in the "functions" subdirectory.
Dependencies of the Vue project must be installed with "npm install" in the main directory. In contrast, dependencies of the Firebase cloud function must be installed with "npm install" being run in the "functions" subdirectory. I had accidentally installed the dependency in the main directory, and was breaking my head trying to understand why it was complaining that it couldn't find the dependency (googleapis) until I realised what I had done. The fix was of course to install it in the right place (so it showed up in the right package.json), and uninstall it from the wrong place for neatness.