11

Commands Used to install:

npm install -g grpc-tools

yarn add global grpc-tools

While trying to install grpc-tools on mac m1 BigSur. I ran into errors pasted below:

npm ERR! code 1
npm ERR! path /Users/abdulmoiz_ahmer/.nvm/versions/node/v16.13.1/lib/node_modules/grpc-tools
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install
npm ERR! response status 404 Not Found on https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.2/darwin-arm64.tar.gz
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using node-pre-gyp@1.0.8
npm ERR! node-pre-gyp info using node@16.13.1 | darwin | arm64
npm ERR! node-pre-gyp info check checked for "/Users/abdulmoiz_ahmer/.nvm/versions/node/v16.13.1/lib/node_modules/grpc-tools/bin/grpc_tools.node" (not found)
npm ERR! node-pre-gyp http GET https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.2/darwin-arm64.tar.gz
npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.2/darwin-arm64.tar.gz 
npm ERR! node-pre-gyp ERR! install error 
npm ERR! node-pre-gyp ERR! stack Error: response status 404 Not Found on https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.2/darwin-arm64.tar.gz
npm ERR! node-pre-gyp ERR! stack     at /Users/abdulmoiz_ahmer/.nvm/versions/node/v16.13.1/lib/node_modules/grpc-tools/node_modules/@mapbox/node-pre-gyp/lib/install.js:67:15
npm ERR! node-pre-gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:96:5)
npm ERR! node-pre-gyp ERR! System Darwin 20.4.0
npm ERR! node-pre-gyp ERR! command "/Users/abdulmoiz_ahmer/.nvm/versions/node/v16.13.1/bin/node" "/Users/abdulmoiz_ahmer/.nvm/versions/node/v16.13.1/lib/node_modules/grpc-tools/node_modules/.bin/node-pre-gyp" "install"
npm ERR! node-pre-gyp ERR! cwd /Users/abdulmoiz_ahmer/.nvm/versions/node/v16.13.1/lib/node_modules/grpc-tools
npm ERR! node-pre-gyp ERR! node -v v16.13.1
npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.8
npm ERR! node-pre-gyp ERR! not ok
Abdulmoiz Ahmer
  • 1,953
  • 17
  • 39

3 Answers3

12

I made it work by setting explicitly the npm_config_target_arch to x64, this is probably not the best solution but for now that's all I found. I ran my npm install like this:

npm_config_target_arch=x64 npm i grpc-tools

if I find a better way I'll update that answer.

Clément Jean
  • 1,735
  • 1
  • 14
  • 32
  • Thank you! 'npm_config_target_arch=x64 npm ci' worked for me – Rayee Roded Aug 09 '22 at 15:49
  • It also works perfectly fine for yarn `npm_config_target_arch=x64 yarn add grpc-tools` – Stefan Sep 26 '22 at 05:32
  • This is the best answer for me! – Pavanraotk Oct 02 '22 at 22:39
  • @clément-jean - I just want to make sure I understand this solution. The problem is the owners of grpc-tools have not compiled an arm64 binary So for the scope of this command-line we're overriding the npm_config_target_arch environment variable to x64. After this command completes - the environment variable npm_config_target_arch will be reset to what it was before running this command? I'm not a shell expert - but don't you need to use two ampersands to make that environment setting stay in scope? example: test=blah && echo $test – Tim Oct 23 '22 at 18:32
  • @Tim You are right that after executing `npm_config_target_arch=x64 npm i grpc-tools`, the npm_config_target_arch variable will be reset. If you want this variable to persist (as long as your shell session), you can use the `&&` operator but I generally prefer using a semicolon like so: `npm_config_target_arch=x64; yarn add grpc-tools`. If you want that variable to persist across reboot, you will have to set that in a file like .bashrc or whatever your shell uses. – Clément Jean Oct 24 '22 at 00:15
  • One thing I realized is that you can't actually use the x64 on an arm64 machine - so this really just "works around the npm install" issue - i.e. npm install will complete successfully - but the binary on your machine will not be executable – Tim Oct 24 '22 at 16:04
  • @Tim You are right on the fact that this is a workaround. However, the binary is executable. You can try the protoc binary like this `./node_modules/grpc-tools/bin/protoc` once you installed it in your nodeJS working directory. – Clément Jean Oct 25 '22 at 00:50
  • I don't think that is true. I don't think you can run binaries built for x64 on arm64. And it is confirmed when I try it in my docker container: root@17079a4c0395:/usr/src/app# ./node_modules/grpc-tools/bin/protoc bash: ./node_modules/grpc-tools/bin/protoc: cannot execute binary file: Exec format error – Tim Oct 25 '22 at 02:15
  • @Tim When running `uname -p` I get `arm`, so my architecture is arm and when I run `file ./node_modules/grpc-tools/bin/protoc`, I get `Mach-O 64-bit executable x86_64` so the binary is x64. And I can run it. This might depend on OSes, not really sure for your case. – Clément Jean Oct 26 '22 at 03:58
6

I was able to work around it by just forcing the x64 binary and letting BigSur deal with it:

yarn add grpc-tools --ignore-scripts
pushd node_modules/grpc-tools
node_modules/.bin/node-pre-gyp install --target_arch=x64
popd

If anyone can find a normal way to install it that would be appreciated.

Abdulmoiz Ahmer
  • 1,953
  • 17
  • 39
2

TL;DR:

softwareupdate --install-rosetta
# Open terminal in x86_64 mode:
arch -x86_64 zsh
source "${NVM_DIR}/nvm.sh"
# Install any another version of node (will be installed x86_x64 version):
nvm install v14
npm install -g grpc-tools

It is problem with package grpc-tools. One of solution for today is using Rosetta. Recommend good tutorial.

Eugen Soloviov
  • 160
  • 1
  • 10