'npm install fails with 'git dep preparation failed' and 'checking for python executable error'

my version

  • node version : 14.19.3
  • npm version : 7.6.0
  • os : macOS Monterey 12.3.1 , M1 chip

Problem

While running npm install with package.json, it keep fails with several errors.
What's even stranger is that there was no problem few hours ago.

Here are my errors

1) npm install
fails with unable to resolve dependency tree

enter image description here

It suggests me to command with --legacy-peer-deps

2) npm install --legacy-peer-deps
fails with git dep preparation failed and python error

9622 verbose stack Error: git dep preparation failed
9622 verbose stack     at ChildProcess.<anonymous> (/Users/myname/.nvm/versions/node/v14.19.3/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
9622 verbose stack     at ChildProcess.emit (events.js:400:28)
9622 verbose stack     at maybeClose (internal/child_process.js:1088:16)
9622 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:296:5)
9623 verbose cwd /Users/myname/Desktop/inpock/link-client
9624 verbose Darwin 21.4.0
9625 verbose argv "/Users/myname/.nvm/versions/node/v14.19.3/bin/node" "/Users/myname/.nvm/versions/node/v14.19.3/bin/npm" "install" "--legacy-peer-deps"
9626 verbose node v14.19.3
9627 verbose npm  v7.6.0
9628 error code 1
9629 error git dep preparation failed
9630 error command /Users/myname/.nvm/versions/node/v14.19.3/bin/node /Users/myname/.nvm/versions/node/v14.19.3/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/Users/myname/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit
9631 error npm WARN using --force Recommended protections disabled.
9631 error npm WARN deprecated [email protected]: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
9631 error npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
9631 error npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
9631 error npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
9631 error npm WARN deprecated [email protected]: this library is no longer supported
9631 error npm WARN deprecated [email protected]: This loader has been deprecated. Please use eslint-webpack-plugin
9631 error npm WARN deprecated [email protected]: "Please update to latest v2.3 or v2.2"
9631 error npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
9631 error npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
9631 error npm WARN deprecated [email protected]: CircularJSON is in maintenance only, flatted is its successor.
9631 error npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated
9631 error npm WARN deprecated [email protected]: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
9631 error npm WARN deprecated [email protected]: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
9631 error npm WARN deprecated [email protected]: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
9631 error npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
9631 error npm WARN deprecated [email protected]: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
9631 error npm WARN deprecated [email protected]: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
9631 error npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
9631 error npm WARN deprecated [email protected]: 3.x is no longer supported
9631 error npm WARN deprecated [email protected]: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
9631 error npm WARN deprecated @hapi/[email protected]: Moved to 'npm install @sideway/address'
9631 error npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
9631 error npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
9631 error npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
9631 error npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
9631 error npm WARN deprecated @hapi/[email protected]: Switch to 'npm install joi'
9631 error npm WARN deprecated [email protected]: This SVGO version is no longer supported. Upgrade to v2.x.x.
9631 error npm WARN deprecated [email protected]: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
9631 error npm WARN deprecated [email protected]: Version no longer supported. Upgrade to @latest
9631 error npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
9631 error npm ERR! code 1
9631 error npm ERR! path /Users/myname/.npm/_cacache/tmp/git-clone-b491e267/node_modules/node-sass
9631 error npm ERR! command failed
9631 error npm ERR! command sh -c node scripts/build.js
9631 error npm ERR! Building: /Users/myname/.nvm/versions/node/v14.19.3/bin/node /Users/myname/.npm/_cacache/tmp/git-clone-b491e267/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
9631 error npm ERR! gyp info it worked if it ends with ok
9631 error npm ERR! gyp verb cli [
9631 error npm ERR! gyp verb cli   '/Users/myname/.nvm/versions/node/v14.19.3/bin/node',
9631 error npm ERR! gyp verb cli   '/Users/myname/.npm/_cacache/tmp/git-clone-b491e267/node_modules/node-gyp/bin/node-gyp.js',
9631 error npm ERR! gyp verb cli   'rebuild',
9631 error npm ERR! gyp verb cli   '--verbose',
9631 error npm ERR! gyp verb cli   '--libsass_ext=',
9631 error npm ERR! gyp verb cli   '--libsass_cflags=',
9631 error npm ERR! gyp verb cli   '--libsass_ldflags=',
9631 error npm ERR! gyp verb cli   '--libsass_library='
9631 error npm ERR! gyp verb cli ]
9631 error npm ERR! gyp info using [email protected]
9631 error npm ERR! gyp info using [email protected] | darwin | x64
9631 error npm ERR! gyp verb command rebuild []
9631 error npm ERR! gyp verb command clean []
9631 error npm ERR! gyp verb clean removing "build" directory
9631 error npm ERR! gyp verb command configure []
9631 error npm ERR! gyp verb check python checking for Python executable "/Users/myname/.pyenv/shims/python" in the PATH
9631 error npm ERR! gyp verb `which` succeeded /Users/myname/.pyenv/shims/python /Users/myname/.pyenv/shims/python
9631 error npm ERR! gyp ERR! configure error
9631 error npm ERR! gyp ERR! stack Error: Command failed: /Users/myname/.pyenv/shims/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
9631 error npm ERR! gyp ERR! stack   File "<string>", line 1
9631 error npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
9631 error npm ERR! gyp ERR! stack                       ^
9631 error npm ERR! gyp ERR! stack SyntaxError: invalid syntax
9631 error npm ERR! gyp ERR! stack
9631 error npm ERR! gyp ERR! stack     at ChildProcess.exithandler (child_process.js:383:12)
9631 error npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
9631 error npm ERR! gyp ERR! stack     at maybeClose (internal/child_process.js:1088:16)
9631 error npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:296:5)
9631 error npm ERR! gyp ERR! System Darwin 21.4.0
9631 error npm ERR! gyp ERR! command "/Users/myname/.nvm/versions/node/v14.19.3/bin/node" "/Users/myname/.npm/_cacache/tmp/git-clone-b491e267/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
9631 error npm ERR! gyp ERR! cwd /Users/myname/.npm/_cacache/tmp/git-clone-b491e267/node_modules/node-sass
9631 error npm ERR! gyp ERR! node -v v14.19.3
9631 error npm ERR! gyp ERR! node-gyp -v v3.8.0
9631 error npm ERR! gyp ERR! not ok
9631 error npm ERR! Build failed with error code: 1
9631 error
9631 error npm ERR! A complete log of this run can be found in:
9631 error npm ERR!     /Users/myname/.npm/_logs/2022-05-18T11_19_20_178Z-debug.log
9632 verbose exit 1

What I have tried

I've tried many other solutions. clean cache and install doesn't work...
I think my python variable or some package has messed up
Here is my zshrc file so please check and any help would be appreciated!

zshrc

export PATH=$HOME/bin:/opt/homebrew/bin:/usr/local/bin:$PATH
export PATH=/usr/local/bin:$PATH # git version
export PATH=$HOME/.pyenv/shims:$PATH

# python
# alias python=/usr/bin/python3
# alias pip=/usr/bin/pip3
# alias python=/usr/local/bin/python3
# alias pip=/usr/local/bin/pip3
alias python="python3"


# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

# pyenv
export PYENV_PATH=$HOME/.pyenv
if which pyenv > /dev/null; then eval "$(pyenv init --path)"; fi
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
eval "$(/opt/homebrew/bin/brew shellenv)"

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

...

and this is what which python shows to me

python: aliased to python3


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source