首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >部署错误Node.js 8。函数部署与以下函数有错误: dialogflowFirebaseFulfillment

部署错误Node.js 8。函数部署与以下函数有错误: dialogflowFirebaseFulfillment
EN

Stack Overflow用户
提问于 2019-06-18 23:42:08
回答 1查看 6.1K关注 0票数 2

试图学习和运行一个非常基本的操作,谷歌助理(2级)在代码库由谷歌。https://codelabs.developers.google.com/codelabs/actions-2/index.html#2

在MB Pro 2018上运行OSX 10.14.5。在终端工作,使用Atom进行文件编辑。

我完成了一级,并得到了各种权限错误和功能实现错误与npm和防火墙。

我无法通过命令简单地安装npm。必须允许我自己安装到正确的文件夹。然后,我必须自己添加依赖项,并在package.json中指向正确的引擎。

最后,我在一个地方,我可以命令安装npm,它完成没有错误。接下来,我尝试使用firebase部署--项目PROJECT_ID。

我得到以下错误

代码语言:javascript
复制
=== 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文件如下

代码语言:javascript
复制
{
  "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

代码语言:javascript
复制
// 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);

谢谢你的帮助!

EN

回答 1

Stack Overflow用户

发布于 2019-06-19 07:44:46

将您的package.json更改为:

编辑:似乎在firebase上缺少了devDependencies

来自firebase-toolspackage.json

代码语言:javascript
复制
"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"
}

在那之后:

代码语言:javascript
复制
npm prune
npm install
npm update

编辑:

您可以尝试这样做,同时安装所有的防火墙:

代码语言:javascript
复制
# 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安装

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56658356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档