Webstorm克隆Git后npm install报错

解决此问题浏览了网上众多方法,现已解决,留作记录(仅适合本文情况)。

一、Git克隆

在git克隆代码后,需要将右下角的分支由main签出为dev。
在这里插入图片描述在这里插入图片描述

二、npm install报错

npm ERR! code 1
npm ERR! path D:\workapp\Webstorm\work\yiwei_admin\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:\Program Files\nodejs\node.exe D:\workapp\Webstorm\work\yiwei_admin\node_modules\node-gyp\bin\node-gyp.js reb
uild --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   'C:\\Program Files\\nodejs\\node.exe',
npm ERR! gyp verb cli   'D:\\workapp\\Webstorm\\work\\yiwei_admin\\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 node-gyp@3.8.0
npm ERR! gyp info using node@16.16.0 | win32 | 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 (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:13:12) 
npm ERR! gyp verb `which` failed     at F (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\isexe\windows.js:36: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 (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:13:12) 
npm ERR! gyp verb `which` failed     at F (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\isexe\windows.js:36: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` failed Error: not found: python
npm ERR! gyp verb `which` failed     at getNotFoundError (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:13:12) 
npm ERR! gyp verb `which` failed     at F (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp verb `which` failed  python Error: not found: python
npm ERR! gyp verb `which` failed     at getNotFoundError (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:13:12) 
npm ERR! gyp verb `which` failed     at F (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at D:\workapp\Webstorm\work\yiwei_admin\node_modules\isexe\windows.js:36: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 could not find "python". checking python launcher
npm ERR! gyp verb could not find "python". guessing location 
npm ERR! gyp verb ensuring that file exists: C:\Python27\python.exe
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
npm ERR! gyp ERR! stack     at PythonFinder.failNoPython (D:\workapp\Webstorm\work\yiwei_admin\node_modules\node-gyp\lib\configure
.js:484:19)
npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (D:\workapp\Webstorm\work\yiwei_admin\node_modules\node-gyp\lib\configure.
js:509:16)
npm ERR! gyp ERR! stack     at callback (D:\workapp\Webstorm\work\yiwei_admin\node_modules\graceful-fs\polyfills.js:306:20)       
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp ERR! System Windows_NT 10.0.19043
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\workapp\\Webstorm\\work\\yiwei_admin\\node_modules\\node-gyp\
\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd D:\workapp\Webstorm\work\yiwei_admin\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.16.0
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!     C:\Users\EDY\AppData\Local\npm-cache\_logs\2022-10-27T07_13_52_936Z-debug-0.log

进程已结束,退出代码1

三、报错原因

package.json文件中dependencies依赖下,node-sass版本为4.14.1,所需node版本应为14,但当前node版本为16,故运行npm install报错。
在这里插入图片描述
在这里插入图片描述

四、解决办法

由于本地已经有一个版本16的node,所以需要安装nvm对node进行版本管理。
1、下载nvm
2、选择安装路径为之前已经安装node的文件路径!!!
3、在cmd命令行窗口中输入nvm -v提示安装版本即安装成功。
4、下载其他版本node(以管理员身份打开cmd ):

nvm list available

查看可安装的NodeJS版本。(建议选择LTS中的版本进行安装)
在这里插入图片描述
然后根据需求安装需要的版本。

nvm install 14.20.1 

nvm ls:列出所有已经在NVM中安装的NodeJS版本。

nvm current:显示当前正在使用的Node版本。

nvm use 14.20.1 :切换NodeJS版本 。

切换完node版本后再次运行npm install即可。

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值