部署错误Node.js 8 ...函数部署有以下功能错误:dialogflowFirebaseFulfillment
Posted
技术标签:
【中文标题】部署错误Node.js 8 ...函数部署有以下功能错误:dialogflowFirebaseFulfillment【英文标题】:Deployment error Node.js 8 ... Functions deploy had errors with the following functions: dialogflowFirebaseFulfillment 【发布时间】:2019-11-01 15:27:03 【问题描述】:尝试在 Google 的代码实验室中为 Google 助理(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 部署 --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);
感谢您的帮助!
【问题讨论】:
尝试使用npm install --save firebase-admin
或将 firebase-admin 移动到依赖项而不是 devDependencies。请务必使用 Node.js 8.13.0 或更高版本。 firebase-admin
试过这个 $ npm install --save firebase-admin + firebase-admin@8.1.0 更新了2个包,7.709s审计了3267个包 发现0个漏洞 部署项目后遇到同样的错误。跨度>
您确定您的 firebase-admin 是在您的依赖项上而不是在您的 devDependencies 上吗?
我不是。这在 Dialogflow 中是否正在实现?我该如何检查?
【参考方案1】:
将您的 package.json 更改为:
编辑:devDependencies
上似乎缺少 firebase
来自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 了解更多选项。
【讨论】:
将我的 package.json 更改为上述内容,然后运行 npm prune 并得到以下错误。npm ERR!文件 /Users/richardr/codelabs-nodejs/level2/functions/package.json npm ERR!代码 EJSONPARSE npm 错误! JSON.parse 无法解析 json npm ERR! JSON.parse Unexpected token : 在位置 14 的 JSON 中,同时在 '"dependencies": npm ERR! JSON.parse "actions-on-...' npm ERR!JSON.parse 无法解析 package.json 数据。npm ERR!JSON.parse package.json 必须是实际的 JSON,而不仅仅是 javascript。 好的,我想我在这里找到了回复firebase-tools以上是关于部署错误Node.js 8 ...函数部署有以下功能错误:dialogflowFirebaseFulfillment的主要内容,如果未能解决你的问题,请参考以下文章
Firebase CLI 部署错误:“部署到 Node.js 10 以下的运行时现在在 Firebase CLI 中被禁用。”
Node.js Heroku 部署 - 无法执行安装后脚本来安装 Bower
AWS 部署 NGINX 连接被拒绝用于 Node.JS 项目