Dialogflow:抛出新错误(`@grpc/grpc-js 仅适用于节点 $supportedNodeVersions`)
Posted
技术标签:
【中文标题】Dialogflow:抛出新错误(`@grpc/grpc-js 仅适用于节点 $supportedNodeVersions`)【英文标题】:Dialogflow: throw new Error(`@grpc/grpc-js only works on Node $supportedNodeVersions`)Dialogflow:抛出新错误(`@grpc/grpc-js 仅适用于节点 $supportedNodeVersions`) 【发布时间】:2019-12-22 22:35:43 【问题描述】:我正在尝试复制 Dialogflow 博客的示例:https://blog.dialogflow.com/post/create-and-manage-entities-with-api/
代码如下:
'use strict';
const admin=require('firebase-admin');
const dialogflow = require('dialogflow');
// Read in credentials from file. To get it, follow instructions here, but
// choose 'API Admin' instead of 'API Client':
// https://dialogflow.com/docs/reference/v2-auth-setup
const credentials = require('./test1drawio.json');
const entitiesClient = new dialogflow.EntityTypesClient(
credentials: credentials,
);
const projectId = 'projectID';
const agentPath = entitiesClient.projectAgentPath(projectId);
const cityEntityType =
displayName: 'city',
kind: 'KIND_MAP',
entities: [
value: 'New York', synonyms: ['New York', 'NYC'],
value: 'Los Angeles', synonyms: ['Los Angeles', 'LA', 'L.A.'],
],
;
const cityRequest =
parent: agentPath,
entityType: cityEntityType,
;
entitiesClient
.createEntityType(cityRequest)
.then((responses) =>
console.log('Created new entity type:', JSON.stringify(responses[0]));
const streetEntityType =
displayName: 'street',
kind: 'KIND_MAP',
entities: [
value: 'Broadway', synonyms: ['Broadway'],
]
;
const streetRequest =
parent: agentPath,
entityType: streetEntityType,
;
return entitiesClient.createEntityType(streetRequest);
)
.then((responses) =>
console.log('Created new entity type:', JSON.stringify(responses[0]));
)
.catch((err) =>
console.error('Error creating entity type:', err);
);
如果我尝试执行它,将抛出答案标题中提到的错误。
我当然检查过 npm、Node 和其他包的版本,这是 package.json 文件:
"name": "tesilaurea",
"version": "1.0.0",
"description": "Tesi di Laurea Dialogflow",
"main": "index.js",
"scripts":
"test": "echo \"Error: no test specified\" && exit 1"
,
"author": "Lorenzo Neri",
"license": "MIT",
"keywords": [],
"dependencies":
"dialogflow": "^0.10.3",
"firebase-admin": "^8.3.0",
"firebase-functions": "3.2.0",
"grpc": "^1.20.2",
"node": "12.8.0"
,
"engines":
"node": "^8.13.0"
我重建、降级并再次尝试执行它,但没有成功。
【问题讨论】:
【参考方案1】:第 1 步。检查您的 NodeJS 版本,-node -v
第 2 步。 将您的节点升级到 LTS 或更高版本,要更新您可以使用 nvm 或 this
第 3 步。
更新后删除 package-lock.json
和 node_modules
文件夹,然后重新安装。
【讨论】:
以上是关于Dialogflow:抛出新错误(`@grpc/grpc-js 仅适用于节点 $supportedNodeVersions`)的主要内容,如果未能解决你的问题,请参考以下文章
在 Firebase Cloud Function 上抛出新函数。 https.HttpsError 被拒绝为客户端上的内部错误