2

Attempting to learn and run a very basic actions for the Google Assistant (Level 2) in codelabs by Google. https://codelabs.developers.google.com/codelabs/actions-2/index.html#2

Running OSX 10.14.5 on a MB Pro 2018. Working in Terminal and using Atom for file editing.

I completed level one and am getting all sorts of permissions errors and function fulfillment errors with npm and firebase.

I was not able to simply install npm through the command npm install. Had to give myself permission to install to the correct folder. Then I had to add dependencies myself as well as point to the correct engine in my package.json

Finally I was at a place where I can command install npm and it completes with no errors. Next I attempt firebase deploy --project PROJECT_ID

I get the following error

=== Deploying to 'actions-codelab-a9731'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (55.46 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: updating Node.js 8 function dialogflowFirebaseFulfillment(us-central1)...
⚠  functions[dialogflowFirebaseFulfillment(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase-admin'

    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/srv/node_modules/firebase-functions/lib/apps.js:25:18)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)


Functions deploy had errors with the following functions:
dialogflowFirebaseFulfillment


To try redeploying those functions, run:
firebase deploy --only functions:dialogflowFirebaseFulfillment


To continue deploying other features (such as database), run:
firebase deploy --except functions

Error: Functions did not deploy properly.
Richards-MacBook-Pro-2:functions richardr$

My pkg.json file is as follows

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "8"
  },
  "scripts": {
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "actions-on-google": "^2.2.0",
    "dialogflow": "^0.6.0",
    "dialogflow-fulfillment": "^0.5.0",
    "firebase-functions": "^3.0.1"
  },
  "devDependencies": {
    "firebase-admin": "^8.1.0",
    "ajv": "^5.5.2",
    "eslint": "^4.19.0",
    "eslint-config-google": "^0.9.1",
    "install-peers": "^1.0.3"
}
}

And this is my index.js

// Copyright 2018, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the 'License');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');

// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
    const luckyNumber = color.length;
// Respond with the user's lucky number and end the conversation.
    conv.close('Your lucky number is ' + luckyNumber);
});

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

Thank you for the help!

4
  • Try yo use npm install --save firebase-admin or to move firebase-admin to dependencies and not devDependencies. Be sure to use Node.js 8.13.0 or higher. firebase-admin Commented Jun 19, 2019 at 0:17
  • Tried this $ npm install --save firebase-admin + [email protected] updated 2 packages and audited 3267 packages in 7.709s found 0 vulnerabilities Got same error after deploying the project. Commented Jun 19, 2019 at 1:25
  • Are u sure that your firebase-admin is on your dependencies and not on your devDependencies? Commented Jun 19, 2019 at 1:28
  • I am not. Is that under fulfillment in Dialogflow? How can I check this? Commented Jun 19, 2019 at 1:29

1 Answer 1

3

Change your package.json to this:

Edit: It seems there is missing firebase on the devDependencies

From firebase-toolspackage.json

"dependencies": {
    "actions-on-google": "^2.2.0",
    "dialogflow": "^0.6.0",
    "dialogflow-fulfillment": "^0.5.0"
  },
  "devDependencies": {
    "ajv": "^5.5.2",
    "eslint": "^4.19.0",
    "eslint-config-google": "^0.9.1",
    "install-peers": "^1.0.3",
    "firebase": "^2.4.2",
    "firebase-admin": "^8.1.0",
    "firebase-functions": "^2.2.1"
}

After that run:

npm prune
npm install
npm update

Edit:

You can try this to install all firebase at once:

# By default npm is set to --save but seems missing -dev on the documentation 
# with only --save this will go in dependencies and not devDependencies
npm install firebase firebase-admin firebase-functions --save-dev

see npm install for more options.

Sign up to request clarification or add additional context in comments.

2 Comments

Changed my package.json to the above and then ran npm prune and got the following errors.npm ERR! file /Users/richardr/codelabs-nodejs/level2/functions/package.json npm ERR! code EJSONPARSE npm ERR! JSON.parse Failed to parse json npm ERR! JSON.parse Unexpected token : in JSON at position 14 while parsing near '"dependencies": { npm ERR! JSON.parse "actions-on-...' npm ERR! JSON.parse Failed to parse package.json data. npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
Ok, I think I found the response here firebase-tools

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.