node.js - 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
我确实得到了结果。
第二次尝试 :
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-cli
通过运行来检索vue create app
。然后,我在 HelloWorld 组件中添加了快速入门指南中显示的基本代码。
我的理论是:由于 gRPC,VueJS 不能使用google-gax模块。你怎么看 ?
解决方案
目前,您正在使用的 Google Cloud API 客户端库无法从浏览器中使用。如您所述,这些库使用 gRPC,而 gRPC 又使用 http2。问题是目前没有主流浏览器允许 JavaScript 库使用 HTTP/2 协议的全部功能,因此目前还没有针对 Node http2 模块的完整浏览器填充程序。
您从 npm 获得的 http2 模块是具有不同 API 的不同库。出于同样的原因,它很可能在浏览器中也不起作用。
推荐阅读
- reactjs - TypeError: player.watermark 在使用 videojs-watermark 时不是函数
- python-3.x - 如何用python打印满足特定条件的txt中的行?
- multithreading - 为什么以不同的顺序解锁两个锁定的银行账户会导致死锁?
- python - Pdf创建和在里面写内容 - PyPDF2
- c# - 文件未正确复制到新位置
- python - 如何在 Python 中的 def __init__ 中检索变量
- php - Activecampaign API - 一次将多个用户添加到列表中?
- excel - 如何拆分和复制其值
- vb.net - 如何使用vb.net删除excel中的特定行
- dart - 颤振数据!= null