TypeError: Cannot read property 'wanted' of undefined:

喜你入骨 提交于 2019-12-03 09:52:21

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!

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;
}

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!

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!