Search code examples
npmnode-modulesnpm-installnode-gyp

npm ERR!: code 127. gyp ERR! stack Error: Command failed


I'm getting the following error while doing npm install:

$ npm install
npm ERR! code 127
npm ERR! path /home/jesusjimenez/projects/project/node_modules/fibers
npm ERR! command failed
npm ERR! command sh -c node build.js || nodejs build.js
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@15.12.0 | linux | x64
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: Command failed: /usr/bin/python3 -c import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack   File "<string>", line 1
npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack                       ^
npm ERR! gyp ERR! stack SyntaxError: invalid syntax
npm ERR! gyp ERR! stack 
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:326:12)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:369:20)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1067:16)
npm ERR! gyp ERR! stack     at Socket.<anonymous> (node:internal/child_process:453:11)
npm ERR! gyp ERR! stack     at Socket.emit (node:events:369:20)
npm ERR! gyp ERR! stack     at Pipe.<anonymous> (node:net:665:12)
npm ERR! gyp ERR! System Linux 5.8.0-48-generic
npm ERR! gyp ERR! command "/usr/bin/node" "/home/jesusjimenez/projects/project/node_modules/.bin/node-gyp" "rebuild" "--release"
npm ERR! gyp ERR! cwd /home/jesusjimenez/projects/project/node_modules/fibers
npm ERR! gyp ERR! node -v v15.12.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok 
npm ERR! node-gyp exited with code: 1
npm ERR! Please make sure you are using a supported platform and node version. If you
npm ERR! would like to compile fibers on this machine please make sure you have setup your
npm ERR! build environment--
npm ERR! Windows + OS X instructions here: https://github.com/nodejs/node-gyp
npm ERR! Ubuntu users please run: `sudo apt-get install g++ build-essential`
npm ERR! RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'` 
npm ERR! Alpine users please run: `sudo apk add python make g++`
npm ERR! sh: 1: nodejs: not found

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/jesusjimenez/.npm/_logs/2021-03-30T21_32_02_097Z-debug.log

I'm not completely sure what is breaking the install, if fibers or somehow that python SyntaxError: invalid syntax However, trying to install fibers individually throws same error. npm i -g fibers doesn't fix, neither changing npm configure set python /path/to/python. Deleting fibers momentarily keeps throwing same Python SyntaxError: invalid syntax error, this time with another node_module.


Solution

  • This is the solution to this issue.

    Explanation:

    Notice this part of your NPM error log:

    npm ERR! gyp ERR! node-gyp -v v3.8.0
    

    This means your code is trying to install node-gyp of the version 3.8.0

    What is probably happening (this was in my case) you have a wrong NodeJS version, for node-gyp.

    I searched for the right version of NodeJS for node-gyp 3.8.0, and the answer is below.

    Solution:

    1. Uninstall current NodeJS version
    2. Install NodeJS Version 6.17.1 (if you need multiple NodeJS versions use NVM tool (Instructions For Windows/Linux/MacOS) https://www.nubo.eu/Install-Multiple-Node-Versions-On-Windows/
    3. Run npm install in your project again