首页 > 解决方案 > 如何在 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"]
  },

方法1dialogflow 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.

我做错了什么或者我该如何纠正?

标签: typescriptionic-frameworkangular7dialogflow-esionic4

解决方案


推荐阅读