I cannot run any project because of gyp error. How can I fix this: npm ERR! gyp verb cli
Asked Answered
W

10

21

Whenever I run my code I always get the same error. I uninstall node and npm and reinstall. But now there is no "node_modules" and I get the same error. How can I fix it?

npm ERR! code 1
npm ERR! path /Users/bng/Desktop/deneme/12-vue-spa/node_modules/node-sass
npm ERR! command failed
npm ERR! command sh -c node scripts/build.js
npm ERR! Building: /usr/local/bin/node /Users/bng/Desktop/deneme/12-vue-spa/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   '/usr/local/bin/node',
npm ERR! gyp verb cli   '/Users/bng/Desktop/deneme/12-vue-spa/node_modules/node-gyp/bin/node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (/Users/bng/Desktop/deneme/12-vue-spa/node_modules/which/which.js:13:12)
npm ERR! gyp verb `which` failed     at F (/Users/bng/Desktop/deneme/12-vue-spa/node_modules/which/which.js:68:19)
npm ERR! gyp verb `which` failed     at E (/Users/bng/Desktop/deneme/12-vue-spa/node_modules/which/which.js:80:29)
npm ERR! gyp verb `which` failed     at /Users/bng/Desktop/deneme/12-vue-spa/node_modules/which/which.js:89:16
npm ERR! gyp verb `which` failed     at /Users/bng/Desktop/deneme/12-vue-spa/node_modules/isexe/index.js:42:5
npm ERR! gyp verb `which` failed     at /Users/bng/Desktop/deneme/12-vue-spa/node_modules/isexe/mode.js:8:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (/Users/bng/Desktop/deneme/12-vue-spa/node_modules/which/which.js:13:12)
npm ERR! gyp verb `which` failed     at F (/Users/bng/Desktop/deneme/12-vue-spa/node_modules/which/which.js:68:19)
npm ERR! gyp verb `which` failed     at E (/Users/bng/Desktop/deneme/12-vue-spa/node_modules/which/which.js:80:29)
npm ERR! gyp verb `which` failed     at /Users/bng/Desktop/deneme/12-vue-spa/node_modules/which/which.js:89:16
npm ERR! gyp verb `which` failed     at /Users/bng/Desktop/deneme/12-vue-spa/node_modules/isexe/index.js:42:5
npm ERR! gyp verb `which` failed     at /Users/bng/Desktop/deneme/12-vue-spa/node_modules/isexe/mode.js:8:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! gyp verb `which` succeeded python /Users/bng/opt/anaconda3/bin/python
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: Command failed: /Users/bng/opt/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:399:12)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:526:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm ERR! gyp ERR! System Darwin 21.4.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/bng/Desktop/deneme/12-vue-spa/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd /Users/bng/Desktop/deneme/12-vue-spa/node_modules/node-sass
npm ERR! gyp ERR! node -v v16.14.2
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok 
npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bng/.npm/_logs/2022-03-24T08_05_44_961Z-debug-0.log

There isn't node-sass and node-gyp. When I tried to install them I also got the same error. I cannot install anything.

Werra answered 24/3, 2022 at 8:19 Comment(4)
What does which -a python2 show when you execute it in your terminal?Purslane
nothing comes out ``` (base) MacBook-Pro:12-vue-spa bng$ which -a python2 (base) MacBook-Pro:12-vue-spa bng$ ```Werra
Ok so it looks like python2 is not installed or cannot be found, but whatever you want to install expects python2 to be installed. So you have to install it using e.g. brew.Purslane
Does this answer your question? Yarn install throws error: gyp verb `which` failed Error: not found: python2Cinematography
C
25

I solved this problem by changing the node version to 14.15.1

Criss answered 25/5, 2022 at 10:42 Comment(3)
In above comments, It is mentionded node 14 works, you can downgrade 14 from hereClishmaclaver
I tried node 18.x but i get the error. downgrading to 14.15.5 solved the issue for me. Ahsant Hamvatan.Universe
NOTE: DOWNGRADING is not a good option! It's like suggesting to go with old version of software that is end of life. Please UPVOTE the answer with yarn remove node-sass yarn add sass. Don't compromise security of your program.Chesson
B
14

Do not use node-sass anymore. Remove 'node-sass' in package.json. pls use 'dart-sass'.

https://www.npmjs.com/package/dart-sass (dart-sass is default now)


update answer at 2023/08/24

the answer still stand. we can see node-sass -> dart-sass -> sass.

now pls use sass https://www.npmjs.com/package/sass

Brade answered 24/3, 2022 at 9:2 Comment(3)
Indeed! Removing node-sass from package.json made npm install finish successfully, finally!Lecia
Also see: https://mcmap.net/q/261103/-node-sass-install-error-with-node-18-versionLecia
'npmjs.com/package/dart-sass' says: "This package has been deprecated. Author message: This package has been renamed to 'sass'."Nagy
C
6

With most of the operating systems removing python2 this is a common issue for most projects. It definitely affected 4/5 of my recent projects after upgrading to current Linux/Debian Stable which removed python2.

The solution is for system to start using python3 and in order to do that you need to..

Solution/Solved is:

node-sass is actually at fault. Python2 is required until version 6.0.0. Normally you would upgrade to latest 7.0.3 but node-sass is currently obsolete, so we will swap to sass project.

yarn remove node-sass
yarn add sass

I've given more details on reasoning why here, or alternative dart-sass if you use "render() and renderSync() functions".:

Solved-ERR!gyp-info-using-node-gyp-3.8.0-gyp-verb-which-failed-Error-not-found-python2

Affected:

  • node.js /react web apps
  • Elixir/Phoenix assets
  • Android apps
  • Vue.js projects
Chesson answered 25/10, 2022 at 17:16 Comment(0)
O
4

Please don't waste your time running the suggested command by others. Please uninstall node.js and use the Node v14.x. It will solve it automatically.

Ostensive answered 27/6, 2022 at 9:12 Comment(0)
H
1

I got the same error and did this:

 1. npm install node-sass
 2. npm install  
 3. npm ci
 4. ng serve --open (to launch the project ).
Hydrobomb answered 4/4, 2022 at 15:32 Comment(0)
E
1

!important

i run into the same issue. ANd What I recomend to you is to install nvm to control your node version instead of unistalling the current version causing other problems with the existent projects.

NVM Installation Guide

https://www.geeksforgeeks.org/how-to-install-and-use-nvm-on-windows/

or

https://tecadmin.net/install-nvm-macos-with-homebrew/

After installation

After you are sure that you'd installed nvm successfully you can do:

  1. nvm --version to check if nvm is successfully installed
  2. nvm install [desired node version] ex.: nvm install 14.0.0
  3. nvm list to check all node versions installed
  4. nvm use [desired version] to change between node version ex.: nvm use 14.0.0

Conclusion

As I mention above, instead of unistalling your node versions you can install different versions of node and changing between then avoid future errors.

Be Happy even with bugs

Eccrine answered 28/9, 2022 at 12:45 Comment(1)
I don't understand the negative vote here it makes perfect sense to manage multiple versions rather than uninstalling. Thank you!Barthelemy
A
0

The following solution works for me.

Try:

npm cache clean --force

npm uninstall node-sass

Uninstall node modules from your project

npm i sass --save
Amboise answered 17/1, 2023 at 7:45 Comment(1)
I think it is generally a "devDependencies" so it should be installed with npm i sass --save-devHaywire
A
0

Please uninstall the nodejs and reinstall the node version 14.21.3

https://nodejs.org/download/release/v14.21.3/

Athena answered 25/3, 2023 at 9:56 Comment(0)
C
0

In a Vue.js app, I encountered the exact same error. Despite trying various methods, the following step proved to be the solution

  1. npm install node-sass
  2. npm install
  3. npm serve
Cockburn answered 21/5 at 19:30 Comment(0)
B
-1

try

  • npm uninstall node-sass --force
  • npm install --save-dev sass --force
  • npm i --force
Billposter answered 27/3 at 9:29 Comment(1)
Please update your answer and add your code to a codeblock. ThanksKuwait

© 2022 - 2024 — McMap. All rights reserved.