尝试在Google的代码实验室中为Google Assistant(第2级)学习和运行非常基本的操作。 https://codelabs.developers.google.com/codelabs/actions-2/index.html#2
在MB Pro 2018上运行OSX 10.14.5。在终端中工作并使用Atom进行文件编辑。
我完成了第一级,并且在npm和firebase中遇到了各种权限错误和功能实现错误。
我无法通过命令npm install简单地安装npm。必须授予自己安装到正确文件夹的权限。然后我必须自己添加依赖项,并指向我的package.json中正确的引擎
最后,我在一个可以命令install npm的地方,它没有错误地完成。接下来我尝试 firebase deploy --project PROJECT_ID
我收到以下错误
=== 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$
我的pkg.json文件如下
{
"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"
}
}
这是我的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);
谢谢您的帮助!
答案 0 :(得分:1)
将您的package.json更改为此:
编辑:firebase
上似乎缺少devDependencies
来自firebase-tools
package.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"
}
运行之后:
npm prune
npm install
npm update
编辑:
您可以尝试以下方法一次安装所有firebase:
# 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
有关更多选项,请参见npm install。