【问题标题】:Module @google-cloud/speech not supported for Vue JS?Vue JS 不支持模块 @google-cloud/speech?
【发布时间】: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


【解决方案1】:

目前,您正在使用的 Google Cloud API 客户端库无法从浏览器中使用。如您所述,这些库使用 gRPC,而 gRPC 又使用 http2。问题是目前没有主流浏览器允许 JavaScript 库使用 HTTP/2 协议的全部功能,因此 Node http2 模块目前没有完整的浏览器 shim。

您从 npm 获得的 http2 模块是具有不同 API 的不同库。出于同样的原因,它很可能在浏览器中也不起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-01
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多