typescript - 如何在 Angular7-Typescript 或 Ionic v4 中配置和使用 dialogflow V2 NodeJS 客户端库?
问题描述
我想使用 Angular Typescript 将我的 Dialogflow 聊天机器人与我现有的 ionic4 应用程序集成,但在导入它以在我的项目中使用时遇到问题。我怎样才能最好地导入对话流 NodeJS 客户端以在我的 Ionic 或 Angular 应用程序中使用?
我开始了一个空白的 Ionic4 Angular 项目并安装了 dialogflow 客户端库:
npm install dialogflow
我还使用以下方法安装了对话框流打字稿:
npm install --save @types/dialogflow
我还将我的tsconfig.app.json更新为;
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": ["node","dialogflow"]
},
方法1:dialogflow docs中的初始化
dialogflow = require('dialogflow');
方法 2:备用初始化
import { SessionsClient } from 'dialogflow';
constructor(public platform: Platform) {
const sessionClient = new SessionsClient();
const sessionPath = sessionClient.sessionPath('project-ID', 'session-ID');
}
在这两种情况下,当我尝试使用该库时,都会出现此错误
在网络应用程序上显示此错误:
Failed to compile.
./node_modules/google-gax/build/src/operationsClient.js
Module not found: Error: Can't resolve './operations_client_config' in '/home/dev/MobileApps/goatChat/node_modules/google-gax/build/src'
在控制台上显示此错误:
ERROR in ./node_modules/google-gax/build/src/operationsClient.js
Module not found: Error: Can't resolve './operations_client_config' in '/home/dev/MobileApps/goatChat/node_modules/google-gax/build/src'
ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'child_process' in '/home/dev/MobileApps/goatChat/node_modules/google-auth-library/build/src/auth'
ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'fs' in '/home/dev/MobileApps/goatChat/node_modules/google-auth-library/build/src/auth'
ERROR in ./node_modules/google-p12-pem/build/src/index.js
Module not found: Error: Can't resolve 'fs' in '/home/dev/MobileApps/goatChat/node_modules/google-p12-pem/build/src'
ERROR in ./node_modules/gtoken/build/src/index.js
Module not found: Error: Can't resolve 'fs' in '/home/dev/MobileApps/goatChat/node_modules/gtoken/build/src'
ERROR in ./node_modules/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in '/home/dev/MobileApps/goatChat/node_modules/request/lib'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'net' in '/home/dev/MobileApps/goatChat/node_modules/forever-agent'
ERROR in ./node_modules/gaxios/node_modules/https-proxy-agent/index.js
Module not found: Error: Can't resolve 'net' in '/home/dev/MobileApps/goatChat/node_modules/gaxios/node_modules/https-proxy-agent'
ERROR in ./node_modules/tough-cookie/lib/cookie.js
Module not found: Error: Can't resolve 'net' in '/home/dev/MobileApps/goatChat/node_modules/tough-cookie/lib'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'net' in '/home/dev/MobileApps/goatChat/node_modules/tunnel-agent'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/home/dev/MobileApps/goatChat/node_modules/forever-agent'
ERROR in ./node_modules/gaxios/node_modules/https-proxy-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/home/dev/MobileApps/goatChat/node_modules/gaxios/node_modules/https-proxy-agent'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/home/dev/MobileApps/goatChat/node_modules/tunnel-agent'
ℹ 「wdm」: Failed to compile.
我做错了什么或者我该如何纠正?
解决方案
推荐阅读
- mysql - 从类别表和其他两个表中获取名称
- r - 向 ggplot Boxplot 添加附加点
- java - org.omg.CORBA.ORBPackage.InvalidName: IDL:omg.org/CORBA/ORB/InvalidName:1.0
- python - 如何在 Python 中动态更改日志文件输出
- linux - Ubuntu 20.04 在访问 NTFS 分区上的某些文件时挂起
- logging - 如何停止 LTPA 令牌 SystemOut.log 中重复出现错误消息
- c - 超出最大递归深度。堆栈溢出异常
- c++ - 将地址清理程序与 MSVC 一起使用时应用程序崩溃
- excel - VBA 自动填充范围调整
- c - C 指针,玩转转换