【发布时间】:2019-05-29 12:06:45
【问题描述】:
我正在使用 Google Cloud API Speech-to-Text Node 客户端库。效果很好,在their documentation 中有很好的描述。 当我想在 VueJS 中使用它时,问题就来了:它似乎不受支持。
第一次尝试:
npm run serve返回
ERROR Failed to compile with 3 errors 11:35:13
This dependency was not found:
* http2 in ./node_modules/@grpc/grpc-js/build/src/channel.js, ./node_modules/@grpc/grpc-js/build/src/subchannel.js and 1 other
但是 http2 现在是 Node 中的核心模块,当我运行 node -p http2 时,我确实得到了结果。
第二次尝试:
npm i http2-
npm run serve返回
WARNING Compiled with 1 warnings 11:41:07
warning in ./node_modules/http2/lib/protocol/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
- 在浏览器中,控制台提供错误
Uncaught Error: not supported
at Root.loadSync (root.js?ee6e:234)
at Object.loadSync (index-light.js?071f:69)
at Object.eval (index.js?f193:244)
at eval (index.js:250)
at Object../node_modules/@grpc/proto-loader/build/src/index.js (app.js:1383)
at __webpack_require__ (app.js:724)
at fn (app.js:101)
at Object.eval (grpc.js?6f5f:34)
at eval (grpc.js:288)
at Object../node_modules/google-gax/build/src/grpc.js
我的 Vue 应用程序是基本的,可以通过运行 vue create app 使用 vue-cli 检索。然后我在 HelloWorld 组件中添加了 the quickstart guide 中显示的基本代码。
我的理论是:由于 gRPC,VueJS 不能使用 google-gax 模块。你怎么看?
【问题讨论】:
-
您从
npm i http2获得的http2 npm 模块与node.js 内置的http2 模块完全不同。它有一个完全不同的 API,不能用作替代品。
标签: node.js vue.js google-cloud-platform grpc google-speech-api