npm install failed at node-sass command failed

npm install 执行后出现如下错误

我维护了一个项目,web页面是使用Angular.js和一些实用程序开发的,但当我使用“npm install”命令时出现了错误,错误日志显示在下面

错误信息

npm ERR! code 1
npm ERR! path D:\FDisk\001-processing\subtlechat-vue\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: D:\Software\200-Brick\210-Tool\218-Node.js\02-Application\node.exe D:\FDisk\001-processing\subtlechat-vue\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   'D:\\Software\\200-Brick\\210-Tool\\218-Node.js\\02-Application\\node.exe',
npm ERR! gyp verb cli   'D:\\FDisk\\001-processing\\subtlechat-vue\\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 [email protected] | 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:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:89:16  
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\isexe\index.js:42:5   
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\isexe\windows.js:36:5 
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:202:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:89:16  
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\isexe\index.js:42:5   
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\isexe\windows.js:36:5 
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:202: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:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:89:16  
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\isexe\index.js:42:5   
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\isexe\windows.js:36:5 
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:202:21)
npm ERR! gyp verb `which` failed  python Error: not found: python
npm ERR! gyp verb `which` failed     at getNotFoundError (D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\which\which.js:89:16  
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\isexe\index.js:42:5   
npm ERR! gyp verb `which` failed     at D:\FDisk\001-processing\subtlechat-vue\node_modules\isexe\windows.js:36:5 
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:202: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:\FDisk\001-processing\subtlechat-vue\node_modules\node-gyp\lib\configure.js:484:19)
npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (D:\FDisk\001-processing\subtlechat-vue\node_modules\node-gyp\lib\configure.js:509:16)
npm ERR! gyp ERR! stack     at callback (D:\FDisk\001-processing\subtlechat-vue\node_modules\graceful-fs\polyfills.js:295:20)
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:202:21)
npm ERR! gyp ERR! System Windows_NT 10.0.19044
npm ERR! gyp ERR! command "D:\\Software\\200-Brick\\210-Tool\\218-Node.js\\02-Application\\node.exe" "D:\\FDisk\\001-processing\\subtlechat-vue\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd D:\FDisk\001-processing\subtlechat-vue\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.18.1
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!     D:\Software\200-Brick\210-Tool\218-Node.js\02-Application\node_cache\_logs\2023-03-13T06_34_38_773Z-debug-0.log

错误分析过程

我上网查阅了很多信息
包括什么node版本问题;或者说一些命令执行方法,和配置node相关文件的权限和环境变量,结果显而易见,都失败了
最后我上网查看了vue和node的官方文档,也尝试了很多次,最后终于解决了这个问题
改Bug就是这样,每个人的错误可能因为一小点小小的差异,而导致大大的不同,在这里我只提供,我所解决的方法,至于是否适用于阁下的错误,还请试试再说

错误解决

这通常是因为运行npm install后环境发生了变化。运行npm rebuild node-sass下载当前环境的绑定。
所以我运行了npm rebuild node-sass,结果成功了!然后安装npm,一切正常。

解决步骤,按顺序执行下列命令,之后直接运行项目就行,不需要再次执行npm install
一:

npm uninstall node-sass

二:

npm i -D sass

三:

npm i

我是将军,我一直都在,。!

猜你喜欢

转载自blog.csdn.net/letterljhx/article/details/129494065