'firebase deploy' not working: "Error parsing triggers: Cannot find module 'firebase-admin'"

3,776 views
Skip to first unread message

Thomas D Kehoe

unread,
Sep 28, 2017, 5:56:05 PM9/28/17
to Firebase Google Group
firebase deploy crashes with this message:

Error parsing triggers: Cannot find module 'firebase-admin'

I have firebase-admin installed globally, not locally:

npm list -g --depth=0                                      
/Users/TDK/.nvm/versions/node/v6.11.2/lib
├── child_process@1.0.2
├── firebase-admin@5.3.0
├── firebase-tools@3.12.0
├── fs@0.0.2
├── npm@5.4.2
└── request@2.83.0

Here's my code:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

Running npm install, npm install firebase-admin, and npm install --save firebase-admin in the local functions directory return this error message:

npm ERR! Cannot read property '0' of undefined


I'm using npm version 5.4.2.

I changed ~5.2.1 to ^5.2.1.

I removed package-lock.json but that didn't fix the problem.

I get the same error message when I do this in the project root directory and in the functions directory.

Any suggestions?

Kato Richardson

unread,
Sep 29, 2017, 1:31:12 PM9/29/17
to Firebase Google Group
Hi Thomas,

Can you reproduce this in a fresh directory with a hello world function? Wondering if it's a versioning/npm issue or something in a config. Also make sure the package.json is in the functions directory and not up a level.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/8df59ae5-c022-4e11-bbeb-39065235895b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Thomas D Kehoe

unread,
Sep 29, 2017, 9:18:50 PM9/29/17
to Firebase Google Group
Thanks, I made a new directory and tested the helloWorld function, it works fine. I'll try swapping out files between the old and new directories.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/8df59ae5-c022-4e11-bbeb-39065235895b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Thomas D Kehoe

unread,
Oct 2, 2017, 1:05:53 PM10/2/17
to Firebase Google Group
Success! Now I'm getting a different error message.:-)

I swapped the new node_modules directory from the helloWorld project, which includes firebase-admin. Then I ran firebase-deploy and got this error message:


functions
: HTTP Error: 400, Change of function trigger type or event provider is not allowed

I got the same error message with the new package.json and the old package.json

This tells me that there's no longer a problem with the node modules. My guess is that firebase-admin wouldn't install locally because I had it installed globally, and firebase deploy apparently can't access global node modules. 

So now I have a new error message, saying that there's something wrong with my function. Can you take a look at it? In my controller under onAuthStateChanged I collect the user.uid and then update that to a database location whenever a user logs in. That code works fine:

firebase.auth().onAuthStateChanged(function(user) { // this runs on login
 
if (user) { // user is signed in
    console
.log("User signed in!");
    $scope
.authData = user;
    firebase
.database().ref('userLoginEvent').update({'user': user.uid}); // update Firebase database to trigger Cloud Function to get a new IBM Watson token
 
} // end if user is signed in
 
else { // User is signed out
    console
.log("User signed out.");
 
}
}); // end onAuthStateChanged

Here's my Cloud Function:

const functions = require('firebase-functions');


const admin = require('firebase-admin');



admin
.initializeApp(functions.config().firebase);


exports
.getWatsonToken = functions.database.ref('/userLoginEvent').onUpdate(event => { // authentication trigger when user logs in


  console
.log("Executing Firebase function!");
  console
.log(event.data.val());


 
var request = require('request');
 
var fs = require('fs');


 
var username = 'groucho',
      password
= 'swordfish',
      url
= 'https://' + username + ':' + password + '@stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api';


  request
({url: url}, function (error, response, body) {


   
var tokenService = "app.value('watsonToken','" + body + "');";


    fs
.writeFile('../public/javascript/services/watsonTokenValue.js', tokenService, (err) => {
     
if (err) throw err;
        console
.log('The file has been saved!');
   
}); // close fs.writeFile


 
}); // close request


}); // close getWatsonToken

Thomas D Kehoe

unread,
Oct 2, 2017, 1:05:54 PM10/2/17
to Firebase Google Group
I found the bug in the trigger: 

exports.getWatsonToken = functions.database.ref('/userLoginEvent').onUpdate(event => {



I removed the slash before userLoginEvent and it seems to work...

Thomas D Kehoe

unread,
Oct 2, 2017, 7:55:45 PM10/2/17
to Firebase Google Group
Everything is working! Thanks!

Kato Richardson

unread,
Oct 2, 2017, 8:00:22 PM10/2/17
to Firebase Google Group
Nice! Great troubleshooting. 

On Mon, Oct 2, 2017 at 4:02 PM, Thomas D Kehoe <thomas...@gmail.com> wrote:
Everything is working! Thanks!

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages