【发布时间】:2017-11-01 09:34:58
【问题描述】:
我正在尝试让 protobuf 在 typescript 中运行。
Google 官方文档说只需使用npm install google-protobuf,然后再使用require('google-protobuf')。
我对 npm 没有经验,所以在那里遇到了几个问题。首先require('google-protobuf')返回错误404,因为文件没有找到。相反,我选择手动要求该文件,因此我在我的 index.html 中找到了它:
<script src="node_modules/google-protobuf/google-protobuf.js"></script>
这应该工作对吗?
相反,我得到了一个Uncaught reference error: exports is not defined。我什至如何开始调试呢?我试图查看 google-protobuf.js 文件,发现了一些 exports 语句,但我不知道我在这里应该做什么。
如果有帮助,这是我的tsconfig.json 文件:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
【问题讨论】:
-
您实际上需要“google-protobuf”。在需要它时,您不应该收到 404 错误。你应该试着把你的精力集中在那里。
标签: javascript typescript npm protocol-buffers