0

Running firebase deploy or firebase deploy --only functions or firebase deploy --only functions:functionName gives me Error: An unexpected error has occurred. Do not mark this question as duplicate because I have searched every single answer given to similar questions and NOTHING solved the problem. I have been using firebase cloud functions successfully last time about a month ago but yesterday I was adding a new function and when I tried to deploy it I got that error. Since then I have uninstalled/installed node maybe 5 times, versions 6.x, 8.x and latest 10.x, I have created new firebase projects, tried deploying "helloworld" function that comes when you initialize cloud functions and nothing has worked.

I download node from here (https://nodejs.org/en/download/), latest version 10.15.3. I know that in cloud functions documentations (https://firebase.google.com/docs/functions/get-started) it says "Cloud Functions can run on either Node v6, or Node v8.", but Doug Stevenson (https://www.youtube.com/watch?v=DYfP-UIKxH0&list=PLl-K7zZEsYLkPZHe41m4jfAxUi0JjLgSM) uses v9.5.0 without problems in this tutorials and I have also tried with multiple v6 and v8 versions after it didn't work with v10 and same problem exists. enter image description here

So after I download it in "D:\node" directory I can run these commands:

C:\Users\PC>node --version
v10.15.3

C:\Users\PC>npm --version
6.4.1

C:\Users\PC>npm version
{ npm: '6.4.1',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.15.3',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.51',
  zlib: '1.2.11' }

Installation has also added npm inside "C:\Users\PC\AppData\Roaming\npm" directory and environment variables for "C:\Users\PC\AppData\Roaming" and "D:\node" Then I go to D:\node directory and run this command:

npm install -g firebase-tools

Then I check firebase version with this

D:\node>firebase --version
6.7.0

Then I do firebase login which shows that I am already logged in, I do firebase list which correctly shows my firebase projects.

Then I create empty folder newFunctions and run this command:

firebase init functions

I choose same project, typescript as language and wait for setup to complete,

import * as functions from 'firebase-functions';

// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
 export const helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!");
 });

That is the default function created in index.ts file, Then I change directory to newFunctions\functions and run this command just like Doug did in that video above:

npm install firebase-functions@latest firebase-admin@latest --save

It added node_modules folder inside functions directory. Then i run firebase deploy (tried with firebase deploy --only functions also) I get this: enter image description here

While looking for answer I found that I can run command with more informations with --debug:

firebase deploy --debug --only functions

and I get this:

+  functions: functions folder uploaded successfully
[2019-04-22T13:44:45.305Z] TypeError: Cannot read property 'match' of undefined
    at exports.getAppEngineLocation (C:\Users\PC\AppData\Roaming\npm\node_modules\firebase-tools\lib\functionsConfig.js:41:27)
    at module.exports (C:\Users\PC\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release.js:83:29)
    at _chain (C:\Users\PC\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\index.js:22:40)
    at C:\Users\PC\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\index.js:69:16
    at process._tickCallback (internal/process/next_tick.js:68:7)

Error: An unexpected error has occurred.

Some people who got similar error resolved problem by using node v6 which I also tried but got the same error. I lost more than 10 hours trying to fix this problem which is not caused by me or my code.

Alen
  • 949
  • 3
  • 17
  • 37
  • Looks like this is an error related to npm itself. Have you tried to remove package-lock.json and to delete the node_modules/ folder before trying to reinstall via `npm install` ? – MichelDelpech Apr 22 '19 at 14:58
  • I just did that and nothing has changed. I deleted package-lock.json file and node_modules folder, then I run npm install in my functions folder, it installed node_modules folder back and after I run firebase deploy I get the same error – Alen Apr 22 '19 at 18:44
  • I have the same proble. I change the target to an other project with this command "firebase use project-id" and the deploy work. When retunning to my original target project the error reappear. It seem like the tools can not retrieve the project location from firebase. – user3634696 Apr 23 '19 at 00:48
  • I just got response from firebase support: "Unfortunately there is an issue on the latest firebase tools, our engineering team is currently working to fix it, in the meantime you can workaround it by downgrading your tools with the following command npm install -g firebase-tools@6.6.0 " This solved my problem, I no longer get that error when trying to deploy functions – Alen Apr 23 '19 at 07:45

2 Answers2

0

Hey i'm not sure if you've got this sorted or not, but i'm just starting out with firebase and cloud functions and going through the tutorial, the very first deploy gave me this error.

I managed to get it working by downgrading my NPM following this post:

TypeError: Cannot read property 'wanted' of undefined:

0

For me, the issue was just that I forgot to cd into the functions folder before running firebase deploy

Pyper
  • 75
  • 1
  • 7