22

I am doing npm install from a project and I am getting this wierd error in node-gyp.

> pty.js@0.2.3 install /home/charizard/Open/terminal-codelearn/node_modules/pty.js
> node-gyp rebuild

npm http GET https://registry.npmjs.org/commander
npm http GET https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/tinycolor
npm http GET https://registry.npmjs.org/options
gyp ERR! configure error 
gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
gyp ERR! stack     at install (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:65:16)
gyp ERR! stack     at Object.self.commands.(anonymous function) [as install] (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:66:37)
gyp ERR! stack     at getNodeDir (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:228:20)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:110:9
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:659:7)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:106:17)
gyp ERR! stack     at maybeClose (child_process.js:773:16)
gyp ERR! stack     at Socket.<anonymous> (child_process.js:986:11)
gyp ERR! stack     at Socket.EventEmitter.emit (events.js:103:17)
gyp ERR! stack     at Pipe.close (net.js:458:12)
gyp ERR! System Linux 3.5.0-37-generic
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/charizard/Open/terminal-codelearn/node_modules/pty.js
gyp ERR! node -v v0.11.8-pre
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok 
npm ERR! weird error 1

When I do npm list, I get this following message.

npm ERR! missing: pty.js@>=0.2.2, required by terminal-codelearn@0.0.3
npm ERR! not ok code 0

Sorry, I am completely new to nodejs.

Charizard_
  • 1,215
  • 1
  • 9
  • 20

6 Answers6

20

The reason this happens is that node-gyp evaluates the -pre part of node@0.11.8-pre as -1. The install then receives a 404 and fails.

gyp http GET http://nodejs.org/dist/v0.8.-1/node-v11.8.-1.tar.gz
gyp http 404 http://nodejs.org/dist/v0.8.-1/node-v11.8.-1.tar.gz

To solve this problem, use a stable release of Node.js. Otherwise, you need to have the Node source lying around, and use the --nodedir flag.

npm install --nodedir=/node/src/

You can read more about this issue here.

hexacyanide
  • 88,222
  • 31
  • 159
  • 162
11

I solved this by upgrading my version of node to a stable version (e.g. not a "pre" version - your version is 0.8.13-pre) with the following:

sudo npm install -g n # install node version manager "n"
sudo n stable # install the latest stable version of node
Pang
  • 9,564
  • 146
  • 81
  • 122
Himanshu sharma
  • 7,487
  • 4
  • 42
  • 75
6

I faced the same problem while installing node-sass as well as windows-build-tools. I was using node-v16.2.0, so it wasn't any -pre release. I also updated to the latest version (node-v16.3.0) but it did not solve my issue either.

Finally, I solved it by uninstalling the existing version and installing the LTS version (v14.17.0 at the time of posting).

Rajorshi Roy
  • 91
  • 2
  • 6
3

I had the same issue. Downgrading to an older version of node version solved the issue. I managed different version of node with nvm. See more details here

nvm list   

    16.10.0
    16.3.0
  * 14.15.0 (Currently using 64-bit executable)
jfk
  • 4,335
  • 34
  • 27
0

I faced the same problem while installing node-sass:

I solved it by uninstalling node-sass:

node uninstall node-sass

And then install it like this, it will work for you:

node install sass --save
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
0

The node-gyp error is a common issue that occurs during npm install when a package requires a native module to be compiled. This error occurs because the native module needs to be compiled on your local machine, but it requires certain tools and dependencies to be installed.

npm install -g node-gyp

If these steps do not resolve the issue, you may need to check the package documentation for any additional instructions or contact the package maintainer for support.

Darshan Malani
  • 478
  • 3
  • 12