Webstorm克隆Git后npm install报错
创始人
2024-03-31 21:40:10
0

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

一、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. (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: 1npm 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即可。

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
客厅放八骏马摆件可以吗(家里摆... 今天给各位分享客厅放八骏马摆件可以吗的知识,其中也会对家里摆八骏马摆件好吗进行解释,如果能碰巧解决你...
苏州离哪个飞机场近(苏州离哪个... 本篇文章极速百科小编给大家谈谈苏州离哪个飞机场近,以及苏州离哪个飞机场近点对应的知识点,希望对各位有...