All Articles

[email protected] 安装问题

1. 问题

安装最新版本[email protected]的时候遇到了不少问题,这里做下记录。

环境:

# OS
# [email protected]
$ node --version
# v10.15.2
$ npm --version
# 6.14.4

安装1.8.1版本的时候,直接使用npm进行会报错:

$ npm install [email protected] -g

npm install [email protected] -g
/usr/local/bin/grpc_tools_node_protoc -> /usr/local/lib/node_modules/grpc-tools/bin/protoc.js
/usr/local/bin/grpc_tools_node_protoc_plugin -> /usr/local/lib/node_modules/grpc-tools/bin/protoc_plugin.js

> [email protected] install /usr/local/lib/node_modules/grpc-tools
> node-pre-gyp install

node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp ERR! install error
node-pre-gyp ERR! stack Error: 503 status code downloading tarball https://node-precompiled-binaries.grpc.io/grpc-tools/v1.8.1/darwin-x64.tar.gz
node-pre-gyp ERR! stack     at PassThrough.<anonymous> (/usr/local/lib/node_modules/grpc-tools/node_modules/node-pre-gyp/lib/install.js:149:27)
node-pre-gyp ERR! stack     at PassThrough.emit (events.js:194:15)
node-pre-gyp ERR! stack     at ClientRequest.<anonymous> (/usr/local/lib/node_modules/grpc-tools/node_modules/needle/lib/needle.js:482:9)
node-pre-gyp ERR! stack     at Object.onceWrapper (events.js:277:13)
node-pre-gyp ERR! stack     at ClientRequest.emit (events.js:189:13)
node-pre-gyp ERR! stack     at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
node-pre-gyp ERR! stack     at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
node-pre-gyp ERR! stack     at Socket.socketOnData (_http_client.js:442:20)
node-pre-gyp ERR! stack     at Socket.emit (events.js:189:13)
node-pre-gyp ERR! stack     at addChunk (_stream_readable.js:284:12)
node-pre-gyp ERR! System Darwin 18.7.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/grpc-tools/node_modules/.bin/node-pre-gyp" "install"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/grpc-tools
node-pre-gyp ERR! node -v v10.15.2
node-pre-gyp ERR! node-pre-gyp -v v0.12.0
node-pre-gyp ERR! not ok
503 status code downloading tarball https://node-precompiled-binaries.grpc.io/grpc-tools/v1.8.1/darwin-x64.tar.gz
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-pre-gyp install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Jonathan/.npm/_logs/2020-04-22T01_31_02_124Z-debug.log

2. 解决

多番尝试之后,直接下载https://github.com/grpc/grpc-node代码到本地,然后将解压文件中的packages/grpc-tools拷贝到/usr/local/lib/node_modules文件夹下。

这样就能使用npm命令检查到这个包了(虽然仍有部分报错信息):

$ npm list -g --depth=0 | grep grpc-tools
# ├── [email protected]
# npm ERR! missing: node-pre-gyp@^0.12.0, required by [email protected]

但实际使用的时候仍旧会有问题:

Error: spawn /usr/local/lib/node_modules/grpc-tools/bin/protoc ENOENT

意思是说找不到包下的bin文件夹下的protoc文件,之前bin文件的链接是这么做的:

/usr/local/bin/grpc_tools_node_protoc -> /usr/local/lib/node_modules/grpc-tools/bin/protoc.js
/usr/local/bin/grpc_tools_node_protoc_plugin -> /usr/local/lib/node_modules/grpc-tools/bin/protoc_plugin.js

包的bin文件夹下面也确实有这两个js文件,但确实没有不带js后缀的bin文件。

然后下载了之前安装错误时候提到的那个tar包:https://node-precompiled-binaries.grpc.io/grpc-tools/v1.8.1/darwin-x64.tar.gz,解压之后发现里面就只有一个bin文件夹,而文件夹内就正好有两个不带js后缀的bin文件,将这两个解压出来的文件放到/usr/local/lib/node_modules/grpc-tools/bin下。后续就能正常使用了。

至于为什么会503报错,以及为什么bin文件夹下有两套文件,这个就暂时先不去考虑了。

EOF

Published 2020/4/22

Some tech & personal blog posts