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

dsenderling
  • 233
  • 2
  • 8
  • 2
    I have looked through quite a few posts about similar looking TypeErrors but unfortunately I have been unable to find any that seemed to be occurring for the same reason as mine. The things I have tried already to fix my problem largely come from other posts here. – dsenderling Jul 03 '19 at 18:31
  • 1
    try to updated f`firebase-tools` to 7.1.1, it worked for me – Matteo Jul 23 '19 at 00:20

6 Answers6

36

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!

Rushabh Vora
  • 551
  • 4
  • 11
8

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;
}
bempa
  • 590
  • 5
  • 9
  • Just tried this on lines 36-38 and I am getting npm ERR! missing script: lint. – dsenderling Jul 03 '19 at 20:01
  • @dsenderling Hmmm strange. Can you gist your file? – bempa Jul 03 '19 at 20:33
  • I noticed that your formating is wrong. You have line-breaks at line24,26. Those should not be there. Did you add those? This is how is should look (without the workaround) https://github.com/firebase/firebase-tools/blob/v7.0.2/src/checkFirebaseSDKVersion.js – bempa Jul 03 '19 at 20:53
  • Thanks for trying, hopefully google comes out with a fix soon, or I might try reverting to an older version of npm to see if that helps or something – dsenderling Jul 03 '19 at 20:53
  • or try to remove / install firebase-tools, then apply the fix again? – bempa Jul 03 '19 at 20:56
  • Those line breaks were left over from me testing the solution that @aaronvargas left. I removed the line breaks and tried again but it didn't help any. – dsenderling Jul 03 '19 at 20:57
  • just tried removing firebase-tools globally and reinstalling globally and trying the fix again and no dice – dsenderling Jul 03 '19 at 21:01
  • Sad to hear. Then downgrading npm is probably the thing to do. – bempa Jul 03 '19 at 21:03
  • 1
    The path in macOS is `/usr/local/lib/node_modules/firebase-tools/lib/checkFirebaseSDKVersion.js`. – michaelgill1969 Jul 04 '19 at 01:24
  • 1
    if you use nvm the file path is like `/.nvm/versions/node/v11.1.0/lib/node_modules/firebase-tools/lib/checkFirebaseSDKVersion.js` – rslvn Jul 04 '19 at 02:29
1

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!

aaronvargas
  • 12,189
  • 3
  • 52
  • 52
  • Thanks for answering, I tried editing that file and now i'm getting a missing script: lint error. It's progress at least. I am new to javascript so I will post the line I edited in case I made a mistake. I ran npm outdated firebase-functions --json=true and got back {}. Also sorry for the bad formatting in this comment I am new to this site and I am having trouble making it pretty child.stdout.on("data", function (data) { if (data && data.toString() !== "{}\n") { output = JSON.parse(data.toString("utf8")); // existing Code! } }); – dsenderling Jul 03 '19 at 19:50
  • It's safer for now to just roll back to previous npm version > npm install -g npm@6.9.2 – TheBosti Jul 05 '19 at 21:54
1

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;
Danny Thuering
  • 101
  • 2
  • 4
1

Try:

npm i -g firebase-tools@latest

Jeff Linahan
  • 3,775
  • 5
  • 37
  • 56
David Ch.
  • 111
  • 4
0

I had the same problem because of old version of Firebase CLI on mac, tried to update using the standard command npm command ==> npm install -g firebase-tools wasn't helpful as it showed that my CLI was updated but deploying function command was picking an old cached version so what worked for me is to use automatic install script to upgrade to the latest version: -

curl -sL firebase.tools | upgrade=true bash

More details can be found on the official doc here

Mussa Charles
  • 4,014
  • 2
  • 29
  • 24