我有一个简单的nodejs
client
,它使用grpc
和protobuf
与cpp
grpc
服务器对话。
我的package.json
包含required
软件包:
"dependencies": {
"google-protobuf": "^3.9.1",
"grpc-web": "^1.0.6",
"webpack": "^4.39.2",
"webpack-cli": "^3.3.7"
}
我运行了npm install
,所有模块都安装在本地node_modules
中。
我的客户端与node_modules
处于同一路径,但是在启动它时,出现错误消息,提示它找不到protobuf模块。
从client.js:
var messages = require('../../messages/proto/output/work_pb.js');
var services = require('../../messages/proto/output/work_grpc_web_pb.js');
var grpc = require('grpc');
运行客户端:
node client.js
Error: Cannot find module 'google-protobuf'
Require stack:
- /home/work/messages/proto/output/work_pb.js
- /home/work/frontend/web/client.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:713:15)
at Function.Module._load (internal/modules/cjs/loader.js:618:27)
at Module.require (internal/modules/cjs/loader.js:771:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/home/radu/work/admass/messages/proto/output/work_pb.js:11:12)
at Module._compile (internal/modules/cjs/loader.js:868:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:879:10)
at Module.load (internal/modules/cjs/loader.js:731:32)
at Function.Module._load (internal/modules/cjs/loader.js:644:12)
at Module.require (internal/modules/cjs/loader.js:771:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/work/messages/proto/output/work_pb.js',
'/home/work/frontend/web/client.js
答案 0 :(得分:0)
删除整个node_modules文件夹并重新安装将起作用:
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'">
答案 1 :(得分:0)
我最终在'../../messages/
内添加了节点模块,并从引用原始文件的步调中删除了该模块,以避免发生冲突。