Node-gyp version is different when using npm install

Viewed 1047

When I run

npm install -g ffi -verbose

it raises error, and log suggests node-gyp version is 8.2.0:

...
npm ERR! D:\Programs\NodeJS\node_global_modules\node_modules\ffi\node_modules\ref\src\binding.cc(644,8): warning C4996: 'Nan::ForceSet': ������Ϊ�ѷ�� [D:\Programs\NodeJS\node_global_modules\node_modules\ffi\node_modules\ref\build\binding.vcxproj]
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.2.0
npm ERR! gyp info using node@16.13.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.8.8 found at "D:\Programs\Anaconda3\python.exe"
npm ERR! gyp info find VS using VS2019 (16.10.31515.178) found at:
npm ERR! gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"
npm ERR! gyp info find VS run with --verbose for detailed information
npm ERR! gyp info spawn D:\Programs\Anaconda3\python.exe
...

This is different from what I see when running node-gyp -v:

C:\Users\Administrator>node-gyp -v
v8.4.1

and could possibly explain why it uses python 3.8 and MSVC 2019 even though I have already run:

npm config set python python2.7
npm config set msvs_version 2015

I don't know why there is another node-gyp on my PC, and how to use the proper version.

2 Answers

Type where node-gyp

You can have a globally installed node-gyp which you probably do and also each package can carry its own version which is probably the case with ffi The PATH determines which one will run

So interesting find, I thought I'd share it here. I was also facing a similar situation where my global node-gyp was 9.0.0 and I had updated the npm node-gyp too like mentioned here . I was using

  • node 16.2.0
  • npm 7.15.1
  • node-gyp 9.0.0

When I ran npm install @abandonware/bleno I got the following error and thought it was npm using the wrong node-gyp version.

416 error code 1
417 error path D:\VSCode Projects\react-native-ble-read-peripheral\food-bank-peripheral\node_modules\@abandonware\bleno
418 error command failed
419 error command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild
420 error gyp info it worked if it ends with ok
420 error gyp info using node-gyp@3.8.0
420 error gyp info using node@16.2.0 | win32 | x64
420 error gyp ERR! configure error
420 error gyp ERR! stack Error: Command failed: C:\Python39\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
420 error gyp ERR! stack   File "<string>", line 1
420 error gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
420 error gyp ERR! stack                       ^
420 error gyp ERR! stack SyntaxError: invalid syntax
420 error gyp ERR! stack
420 error gyp ERR! stack     at ChildProcess.exithandler (node:child_process:326:12)
420 error gyp ERR! stack     at ChildProcess.emit (node:events:365:28)
420 error gyp ERR! stack     at maybeClose (node:internal/child_process:1067:16)
420 error gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
420 error gyp ERR! System Windows_NT 10.0.19044
420 error gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\VSCode Projects\\react-native-ble-read-peripheral\\food-bank-peripheral\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
420 error gyp ERR! cwd D:\VSCode Projects\react-native-ble-read-peripheral\food-bank-peripheral\node_modules\@abandonware\bleno
420 error gyp ERR! node -v v16.2.0
420 error gyp ERR! node-gyp -v v3.8.0
420 error gyp ERR! not ok
421 verbose exit 1

But then I saw this comment here and here so I went back to look at the log file and saw that the actual error started above here (line 409)

409 verbose stack Error: command failed
409 verbose stack     at ChildProcess.<anonymous> (C:\Users\Ramlah\AppData\Roaming\nvm\v16.2.0\node_modules\npm\node_modules\@npmcli\run-script\node_modules\@npmcli\promise-spawn\index.js:64:27)
409 verbose stack     at ChildProcess.emit (node:events:365:28)
409 verbose stack     at maybeClose (node:internal/child_process:1067:16)
409 verbose stack     at Socket.<anonymous> (node:internal/child_process:453:11)
409 verbose stack     at Socket.emit (node:events:365:28)
409 verbose stack     at Pipe.<anonymous> (node:net:661:12)
410 verbose pkgid @abandonware/bleno@0.5.1-3
411 verbose cwd D:\VSCode Projects\react-native-ble-read-peripheral\food-bank-peripheral
412 verbose Windows_NT 10.0.19044
413 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
414 verbose node v16.2.0
415 verbose npm  v7.15.1
416 error code 1
417 error path D:\VSCode Projects\react-native-ble-read-peripheral\food-bank-peripheral\node_modules\@abandonware\bleno
418 error command failed
419 error command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild

So I downgraded my node version using nvm from 16.2.0 to 14.17.1 (and this also downgraded my npm version to 6.14.13) and viola! My npm install worked just fine.

Related