firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Error occurred while parsing your function triggers.

Open chezdrz opened this issue 8 years ago • 15 comments

node --version
v8.9.4

npm --version
5.6.0

firebase --version
3.17.4

firebase deploy --only functions

=== Deploying to 'xxxxxx'...

i deploying functions Running command: npm --prefix $RESOURCE_DIR run lint

functions@ lint /Users/xx/Documents/Drive/AppDev/firebase/xxxx/functions eslint .

✔ functions: Finished running predeploy script. i functions: ensuring necessary APIs are enabled... ✔ functions: all necessary APIs are enabled i functions: preparing functions directory for uploading...

Error: Error occurred while parsing your function triggers.

ReferenceError: firebase is not defined at Object. (/Users/xxxxx/Documents/Drive/AppDev/firebase/xxxxx/functions/index.js:12:3) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11 at Object. (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:38:3)

Content of my index.js index.js


const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

  var config = {
    apiKey: "Alxxxxxxxxxxxxxxxx",
    authDomain: "xxxxxx.firebaseapp.com",
    databaseURL: "https://xxxxx.firebaseio.com"
  };


  firebase.initializeApp(config);

 exports.queryDb = functions.https.onRequest((req,res) =>
 {
   const text = req.query.text;

   console.log('Value of the text >' + text);
   res.send("Return value " + text  );
 });

The error is at this line firebase.initializeApp(config); If I comment that line , then the func deploys fine. I saw a similar thread, but whatever was listed there did not fix my problem. Any pointers would be much appreciated. I am on a mac.

Note: I xxxxx'd out the project and user details in the description above.

chezdrz avatar Feb 24 '18 08:02 chezdrz

Additional details . My package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "./node_modules/.bin/eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "firebase": "^4.10.1",
    "firebase-admin": "~5.8.1",
    "firebase-functions": "^0.8.1"
  },
  "devDependencies": {
    "eslint": "^4.12.0",
    "eslint-plugin-promise": "^3.6.0"
  },
  "private": true
}

chezdrz avatar Feb 24 '18 10:02 chezdrz

Does this have anything to do with the Database Rules you setup in your Firebase Project setting ?

chezdrz avatar Feb 24 '18 14:02 chezdrz

Hi, you should take another look at the quick start guides for the Firestore and Firebase Functions, they are really great. The error message is clear, you’re calling firebase.initializeApp, but you’ve required firebase-admin as admin. What’s more, you’re actually initializing the admin SDK immediately after requiring it, you don’t have to do it twice.

It’s just a problem with your code, not this package.

Please close the issue and if you will come across some other problems, it’s better to ask such questions on StackOverflow. GitHub is meant to track issues within the packages themselve.

merlinnot avatar Feb 24 '18 16:02 merlinnot

Thank you. I went through the quick start guide and resolved this.

chezdrz avatar Feb 24 '18 17:02 chezdrz

hey you guys just need to return null in your then statement like this

let params = {...};
var firestore = admin.firestore();
var dbRef = firestore.collection('your-collection-name');

  dbRef
    .add(params)
    .then((docRef) => {
      console.log("doc added with ID ", docRef.id);

      return null
    })
    .catch((err) => {
      console.error("Error in adding document ", err);
    });

mohd7469 avatar Mar 24 '18 12:03 mohd7469

@chezdrz I'm running into this error. How did you solve this?

dimitri320 avatar Apr 06 '18 14:04 dimitri320

Me too

wlaa41 avatar Jun 22 '18 02:06 wlaa41

what is version of your node.js and npm ?

mohd7469 avatar Jun 22 '18 05:06 mohd7469

i face same problem here how can i solved ?please help

`✖ 2 problems (0 errors, 2 warnings)

✔ functions: Finished running predeploy script. i functions: ensuring necessary APIs are enabled... ✔ functions: all necessary APIs are enabled i functions: preparing functions directory for uploading...

Error: Error occurred while parsing your function triggers.`

BLACKCAT25896 avatar Nov 01 '19 11:11 BLACKCAT25896

add cross-env NODE_ENV=production to the beginning of the deploy script

maysam avatar Jul 02 '20 14:07 maysam

What is the origin of this problem? because my problem is generated when I use ng deploy with @angular/fire and there I don't know where control the function

jgu7man avatar Jul 12 '20 15:07 jgu7man

I had this problem and It was solved when I switched my local node version from 13.2.0 to 14.13.0

luisVargasGu avatar Nov 20 '20 21:11 luisVargasGu

Any solution yet?

SyedUmerHasan avatar Nov 26 '21 14:11 SyedUmerHasan

There are several reasons why parsing function trigger may fail. I'd recommend running firebase deploy with --debug flag or sharing additional info available on firebase-debug.log to help us pinpoint the issue.

taeold avatar Nov 26 '21 20:11 taeold

I also got this error message and in my case I had a circular dependency in my code

sirkrisp avatar Apr 12 '22 21:04 sirkrisp