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