14

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.

Jesus Jimenez
  • 351
  • 1
  • 3
  • 13
  • Solved [as here](https://stackoverflow.com/a/49536033/13784272) downgrading node version [as here](https://stackoverflow.com/a/7718438/13784272). – Jesus Jimenez Mar 31 '21 at 00:38

4 Answers4

8

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
Stas Sorokin
  • 3,029
  • 26
  • 18
1

I got this error when I set a PATH variable incorrectly which meant npm and node couldn't be found correctly.

To diagnose this, I ran

npm --version
node --version

It said command not found, so I checked env | grep PATH which showed me that the location of npm and node weren't on PATH as they needed to be. Once I fixed that, everything worked as expected.

stevec
  • 41,291
  • 27
  • 223
  • 311
0

I got the same/similar issue without making any changes to version of node. I hate to be that guy, but after a day of struggling with it I decided to restart my machine. That fixed it...

Scr0t
  • 21
  • 5
0

The issue is that node-gyp tries to build with Python 2 syntax: print "%s.%s.%s" % sys.version_info[:3]; which throws an error probably because you have Python 3 on your computer.

This usually occurs when installing an outdated npm module which is not compatible with the current Node version on your system. Try installing Python 2 and set it to the path, or locate the offending module in package.json and then upgrade the version number to the one that is compatible with your current Node version.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Erisan Olasheni
  • 2,395
  • 17
  • 20