npm install parcel installation failed

171 Views Asked by At

Running npm install --save-dev parcel in an npm project on my computer returns the following log:

npm WARN deprecated [email protected]: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm ERR! code 1
npm ERR! path /Users/xxxxxx/Desktop/test/node_modules/@parcel/watcher
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | x64
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: Command failed: /Users/xxxxxx/anaconda3/bin/python -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:422:12)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:514:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1105:16)
npm ERR! gyp ERR! stack     at Socket.<anonymous> (node:internal/child_process:457:11)
npm ERR! gyp ERR! stack     at Socket.emit (node:events:514:28)
npm ERR! gyp ERR! stack     at Pipe.<anonymous> (node:net:337:12)
npm ERR! gyp ERR! System Darwin 22.5.0
npm ERR! gyp ERR! command "/Users/xxxxxx/.nvm/versions/node/v20.9.0/bin/node" "/Users/xxxxxx/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/xxxxxx/Desktop/test/node_modules/@parcel/watcher
npm ERR! gyp ERR! node -v v20.9.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in: /Users/xxxxxx/.npm/_logs/2024-02-18T18_19_28_422Z-debug-0.log

Not sure how to resolve this. I've read it may be a problem with svgo, I was looking at node-gyp possible issues, but I'm still not sure how to fix this. Any help is much appreciated!

4

There are 4 best solutions below

0
Liap On

It seems like your nodeJs is missing some tools when installing the nodeJs.

Try to reinstall nodeJs and check the checkbox to install the necessary tools

enter image description here

Or you can use this command to install the necessary tools without reinstalling nodeJs. But the first solution is better

Please note that the official Node.js for Windows installer can now automatically install the required tools. That's likely a much better option than the module listed here (windows-build-tools).

npm install --global windows-build-tools
0
Alex Nikulin On

What I understand about your env from attached logs:

  1. Your system is probably Mac OS Ventura 13.5
  2. Your device is 12 inch MacBook (from 2015 to 2019 year)
  3. Your processor is x64
  4. NodeJs 20.9.0
  5. Node-gyp 3.8.0
  6. Python 3.x
  7. Probably no XCode or C++ compiler installed

npm packages in some cases depend on some native modules (C++, Python). In your case npm is trying to build python module, and that module requires python "2.x" , but in your env is python "3.x"

https://stackoverflow.com/a/14159415/5138198 Here is an explanation of python error

https://github.com/parcel-bundler/watcher/tree/v2.0.2 Here a module that trigger error

https://github.com/nodejs/node-gyp Here is a module page, and that node module builds python, c++ etc...

Try to install C++ compiler : https://support.wolfram.com/12799?src=system-modeler

OR

Please read an article about python env at node-gyp page. Or simply downgrade your python version to "2.x". https://github.com/nodejs/node-gyp

P.S. Parcel -> requires parcel-watcher module (includes C++ files at package) -> requires node-gyp -> node-gyp tries to build "parcel-watcher" and being unable to find C++ compiler and tries alternatively do it through python

There are all my thoughts

1
Chester Reynolds On

What is your python version? You need to install python 3 or if you have both version you can set python 3 using npm like this.

npm config set python python3

Try to update node-gyp version.

 npm install -g node-gyp

Sometimes the npm cache can cause issues. So clear cache.

npm cache clean --force

And then try to reinstall parcel.

npm install --save-dev parcel
0
Hamid On

The error message you're encountering indicates an issue with node-gyp, which is used to build native addons for Node.js projects. Here's how to troubleshoot and potentially fix it:

Force Python 3 for node-gyp:

Set the PYTHON environment variable to your Python 3 executable path before running npm install:

export PYTHON=/path/to/your/python3  # Replace with actual path
npm install --save-dev parcel

Try reinstalling node-gyp globally:

npm uninstall -g node-gyp
npm install -g node-gyp