TypeError: Cannot read property 'wanted' of undefined:

前端 未结 5 2399
面向向阳花
面向向阳花 2021-02-12 09:22

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 t

相关标签:
5条回答
  • 2021-02-12 10:01

    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!

    0 讨论(0)
  • 2021-02-12 10:13

    Try:

    npm i -g firebase-tools@latest

    0 讨论(0)
  • 2021-02-12 10:18

    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;
    }
    
    0 讨论(0)
  • 2021-02-12 10:23

    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;
    
    0 讨论(0)
  • 2021-02-12 10:24

    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!

    0 讨论(0)
提交回复
热议问题