I'm trying to use gRPC with javascript. I want to use the gRPC package, as I need to send some metadata, but I get an error when I'm using require('grpc').
Here's the error message: Can't resolve 'child_process'
ERROR in ./node_modules/detect-libc/lib/detect-libc.js
Module not found: Error: Can't resolve 'child_process' in '/home/sglab/dev/grpc-web/client/node_modules/detect-libc/lib'
@ ./node_modules/detect-libc/lib/detect-libc.js 4:16-40
@ ./node_modules/node-pre-gyp/lib/util/versioning.js
@ ./node_modules/node-pre-gyp/lib/pre-binding.js
@ ./node_modules/grpc/src/grpc_extension.js
@ ./node_modules/grpc/index.js
@ ./client.js
ERROR in ./node_modules/detect-libc/lib/detect-libc.js
Module not found: Error: Can't resolve 'fs' in '/home/sglab/dev/grpc-web/client/node_modules/detect-libc/lib'
@ ./node_modules/detect-libc/lib/detect-libc.js 5:18-31
@ ./node_modules/node-pre-gyp/lib/util/versioning.js
@ ./node_modules/node-pre-gyp/lib/pre-binding.js
@ ./node_modules/grpc/src/grpc_extension.js
@ ./node_modules/grpc/index.js
@ ./client.js
ERROR in ./node_modules/fs.realpath/old.js
Module not found: Error: Can't resolve 'fs' in '/home/sglab/dev/grpc-web/client/node_modules/fs.realpath'
@ ./node_modules/fs.realpath/old.js 24:9-22
@ ./node_modules/fs.realpath/index.js
@ ./node_modules/glob/glob.js
@ ./node_modules/rimraf/rimraf.js
@ ./node_modules/node-pre-gyp/lib/util/napi.js
@ ./node_modules/node-pre-gyp/lib/pre-binding.js
@ ./node_modules/grpc/src/grpc_extension.js
@ ./node_modules/grpc/index.js
@ ./client.js
ERROR in ./node_modules/glob/glob.js
Module not found: Error: Can't resolve 'fs' in '/home/sglab/dev/grpc-web/client/node_modules/glob'
@ ./node_modules/glob/glob.js 43:9-22
@ ./node_modules/rimraf/rimraf.js
@ ./node_modules/node-pre-gyp/lib/util/napi.js
@ ./node_modules/node-pre-gyp/lib/pre-binding.js
@ ./node_modules/grpc/src/grpc_extension.js
@ ./node_modules/grpc/index.js
@ ./client.js
ERROR in ./node_modules/glob/sync.js
Module not found: Error: Can't resolve 'fs' in '/home/sglab/dev/grpc-web/client/node_modules/glob'
@ ./node_modules/glob/sync.js 4:9-22
@ ./node_modules/glob/glob.js
@ ./node_modules/rimraf/rimraf.js
@ ./node_modules/node-pre-gyp/lib/util/napi.js
@ ./node_modules/node-pre-gyp/lib/pre-binding.js
@ ./node_modules/grpc/src/grpc_extension.js
@ ./node_modules/grpc/index.js
@ ./client.js
ERROR in ./node_modules/grpc/index.js
Module not found: Error: Can't resolve 'fs' in '/home/sglab/dev/grpc-web/client/node_modules/grpc'
@ ./node_modules/grpc/index.js 22:9-22
@ ./client.js
ERROR in ./node_modules/grpc/src/grpc_extension.js
Module not found: Error: Can't resolve 'fs' in '/home/sglab/dev/grpc-web/client/node_modules/grpc/src'
@ ./node_modules/grpc/src/grpc_extension.js 34:11-24
@ ./node_modules/grpc/index.js
@ ./client.js
ERROR in ./node_modules/rimraf/rimraf.js
Module not found: Error: Can't resolve 'fs' in '/home/sglab/dev/grpc-web/client/node_modules/rimraf'
@ ./node_modules/rimraf/rimraf.js 6:9-22
@ ./node_modules/node-pre-gyp/lib/util/napi.js
@ ./node_modules/node-pre-gyp/lib/pre-binding.js
@ ./node_modules/grpc/src/grpc_extension.js
@ ./node_modules/grpc/index.js
@ ./client.js
The problems shows when I use this line: var grpc = required('grpc') and this command: npx webpack <file>.
Here's package.json file:
{
"name": "example",
"version": "0.1.0",
"description": "example",
"devDependencies": {
"@grpc/proto-loader": "^0.3.0",
"google-protobuf": "^3.6.1",
"grpc": "^1.24.4",
"grpc-web": "^1.0.0",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0"
}
}
I'm not really familiar with node.js, so it would be great if someone could explain it to me.
Thanks in advance for help!