问题
I have been deploying functions with firebase successfully all day learning how to use it. I was trying to see what happened if I initialized another directory that deploys to the same project and had no problems until i updated my npm version and now I am getting "Unexpected error has occurred" whenever I try to deploy
I have tried updating npm permission by making my own user the owner of the node_modules, bin, and share directories. I have tried uninstalling and reinstalling firebase-tools. I have also tried deleting all my current function directories and initializing a fresh directory and reinstalling my dependencies in there fresh.
Here is the debug log
Dylans-MacBook-Pro-3:functions dsenderling$ firebase deploy --debug
[2019-07-03T18:04:35.526Z] ----------------------------------------------------------------------
[2019-07-03T18:04:35.528Z] Command: /usr/local/bin/node /usr/local/bin/firebase deploy --debug
[2019-07-03T18:04:35.529Z] CLI Version: 7.0.2
[2019-07-03T18:04:35.529Z] Platform: darwin
[2019-07-03T18:04:35.529Z] Node Version: v10.16.0
[2019-07-03T18:04:35.529Z] Time: Wed Jul 03 2019 13:04:35 GMT-0500 (Central Daylight Time)
[2019-07-03T18:04:35.529Z] ----------------------------------------------------------------------
[2019-07-03T18:04:35.537Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2019-07-03T18:04:35.537Z] > authorizing via signed-in user
[2019-07-03T18:04:35.537Z] [iam] checking project my-awesome-project-5a4e9 for permissions ["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]
[2019-07-03T18:04:35.539Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/my-awesome-project-5a4e9:testIamPermissions
permissions=[cloudfunctions.functions.create, cloudfunctions.functions.delete, cloudfunctions.functions.get, cloudfunctions.functions.list, cloudfunctions.functions.update, cloudfunctions.operations.get, firebase.projects.get]
[2019-07-03T18:04:35.769Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Wed, 03 Jul 2019 18:04:35 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, server-timing=gfet4t7; dur=83, alt-svc=quic=":443"; ma=2592000; v="46,43,39", accept-ranges=none, transfer-encoding=chunked
[2019-07-03T18:04:37.033Z] TypeError: Cannot read property 'wanted' of undefined
at /usr/local/lib/node_modules/firebase-tools/lib/checkFirebaseSDKVersion.js:37:51
at process._tickCallback (internal/process/next_tick.js:68:7)
Error: An unexpected error has occurred.
My gut tells me there is something wrong with firebase-tools or my firebase sdk but I can't figure out what. Thanks in advance
回答1:
Had the exact same problem, started right after updating npm from 6.9.2 to 6.10.0.
Ended up downgrading back to 6.9.2 (npm install -g npm@6.9.2), and my firebase deploys started working again, right away.
Edit : firebase deploys are working with npm 6.10.1, safe to update now!
回答2:
I think this issue is caused by a fix in npm 6.10.0, see https://github.com/npm/cli/pull/176.
A workaround is to modify /usr/lib/node_modules/firebase-tools/lib/checkFirebaseSDKVersion.js
(linux).
For macOS and nvm, see comments below.
from:
if (!output) {
return;
}
to:
if (!output || !output["firebase-functions"]) {
return;
}
回答3:
This just started happening to me also...
Looks like either npm
is outputting a different result for this command
npm outdated firebase-functions --json=true
// for me outputs {}\n
And the script checkFirebaseSDKVersion.js
is expecting something like this (which it would get if your firebase-functions WAS actually out of date)
{
"current": "2.5.0",
"wanted": "2.5.0",
"latest": "3.0.2",
"location": "node_modules/some path /firebase-functions"
}
OR a blank output... more likely in your case
What you can do to 'Fix' it
This will probably get fixed pretty soon as it start affecting more people...
for now
modify
/usr/local/lib/node_modules/firebase-tools/lib/checkFirebaseSDKVersion.js
add this to account for the updated empty output of {}\n
around line 24
if (data && data.toString() !== "{}\n") {
output = JSON.parse(data.toString("utf8")); // existing Code!
}
Not sure how the update process works for npm, so you might have to revert this to update it when fixed, but I don't think so.
Hope that helps!
回答4:
Had the same issue with npm@6.12.0 and firebase-functions@3.3.0.
TypeError: Cannot read property 'wanted' of undefined
at /usr/local/lib/node_modules/firebase-tools/lib/checkFirebaseSDKVersion.js:37:51
at process._tickCallback (internal/process/next_tick.js:68:7)
Fixed by changing in /usr/local/lib/node_modules/firebase-tools/lib/checkFirebaseSDKVersion.js
line #37.
var wanted = (output["firebase-functions"] || {}).wanted;
var latest = (output["firebase-functions"] || {}).latest;
来源:https://stackoverflow.com/questions/56875994/typeerror-cannot-read-property-wanted-of-undefined