首页 > 解决方案 > Vue JS 不支持模块 @google-cloud/speech?

问题描述

我正在使用 Google Cloud API Speech-to-Text Node 客户端库。效果很好,并且在他们的文档中有很好的描述。当我想在 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我确实得到了结果。

第二次尝试 :

 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-cli通过运行来检索vue create app。然后,我在 HelloWorld 组件中添加了快速入门指南中显示的基本代码。

我的理论是:由于 gRPC,VueJS 不能使用google-gax模块。你怎么看 ?

标签: node.jsvue.jsgoogle-cloud-platformgrpcgoogle-speech-api

解决方案


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

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


推荐阅读