npm 安装失败,node-sass 命令执行失败。

8
作为标题。我维护了一个使用Angular.js和一些实用程序开发的网页项目,但当我使用“npm install”命令时出现了一些问题,并显示了以下错误日志...
2094 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Gary.Lu\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install"
2095 verbose node v16.13.1
2096 verbose npm  v8.3.0
2097 error code 1
2098 error path C:\Users\Gary.Lu\Documents\ITTS Projects\AXMES\MAIN\ITTS-MES\WEB\node_modules\node-sass
2099 error command failed
2100 error command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js
2101 error Building: C:\Program Files\nodejs\node.exe C:\Users\Gary.Lu\Documents\MyWeb\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
2102 error gyp info it worked if it ends with ok
2102 error gyp verb cli [
2102 error gyp verb cli   'C:\\Program Files\\nodejs\\node.exe',
2102 error gyp verb cli   'C:\\Users\\Gary.Lu\\Documents\\MyWeb\\node_modules\\node-gyp\\bin\\node-gyp.js',
2102 error gyp verb cli   'rebuild',
2102 error gyp verb cli   '--verbose',
2102 error gyp verb cli   '--libsass_ext=',
2102 error gyp verb cli   '--libsass_cflags=',
2102 error gyp verb cli   '--libsass_ldflags=',
2102 error gyp verb cli   '--libsass_library='
2102 error gyp verb cli ]
2102 error gyp info using node-gyp@3.8.0
2102 error gyp info using node@16.13.1 | win32 | x64
2102 error gyp verb command rebuild []
2102 error gyp verb command clean []
2102 error gyp verb clean removing "build" directory
2102 error gyp verb command configure []
2102 error gyp verb check python checking for Python executable "python2" in the PATH
2102 error gyp verb `which` failed Error: not found: python2
2102 error gyp verb `which` failed     at getNotFoundError (C:\Users\Gary.Lu\Documents\MyWeb\node_modules\which\which.js:13:12)
2102 error gyp verb `which` failed     at F (C:\Users\Gary.Lu\Documents\MyWeb\node_modules\which\which.js:68:19)
2102 error gyp verb `which` failed     at E (C:\Users\Gary.Lu\Documents\MyWeb\node_modules\which\which.js:80:29)
2102 error gyp verb `which` failed     at C:\Users\Gary.Lu\Documents\MyWeb\node_modules\which\which.js:89:16
2102 error gyp verb `which` failed     at C:\Users\Gary.Lu\Documents\MyWeb\node_modules\isexe\index.js:42:5
2102 error gyp verb `which` failed     at C:\Users\Gary.Lu\Documents\MyWeb\node_modules\isexe\windows.js:36:5
2102 error gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
2102 error gyp verb `which` failed  python2 Error: not found: python2
2102 error gyp verb `which` failed     at getNotFoundError (C:\Users\Gary.Lu\Documents\MyWeb\node_modules\which\which.js:13:12)
2102 error gyp verb `which` failed     at F (C:\Users\Gary.Lu\Documents\MyWeb\node_modules\which\which.js:68:19)
2102 error gyp verb `which` failed     at E (C:\Users\Gary.Lu\Documents\MyWeb\node_modules\which\which.js:80:29)
2102 error gyp verb `which` failed     at C:\Users\Gary.Lu\Documents\MyWeb\node_modules\which\which.js:89:16
2102 error gyp verb `which` failed     at C:\Users\Gary.Lu\Documents\MyWeb\node_modules\isexe\index.js:42:5
2102 error gyp verb `which` failed     at C:\Users\Gary.Lu\Documents\MyWeb\node_modules\isexe\windows.js:36:5
2102 error gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
2102 error gyp verb `which` failed   code: 'ENOENT'
2102 error gyp verb `which` failed }
2102 error gyp verb check python checking for Python executable "python" in the PATH
2102 error gyp verb `which` succeeded python C:\Python310\python.EXE
2102 error gyp ERR! configure error 
2102 error gyp ERR! stack Error: Command failed: C:\Python310\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
2102 error gyp ERR! stack   File "<string>", line 1
2102 error gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
2102 error gyp ERR! stack                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2102 error gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
2102 error gyp ERR! stack 
2102 error gyp ERR! stack     at ChildProcess.exithandler (node:child_process:397:12)
2102 error gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
2102 error gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)
2102 error gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
2102 error gyp ERR! System Windows_NT 10.0.19044
2102 error gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Gary.Lu\\Documents\\MyWeb\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
2102 error gyp ERR! cwd C:\Users\Gary.Lu\Documents\MyWeb\node_modules\node-sass
2102 error gyp ERR! node -v v16.13.1
2102 error gyp ERR! node-gyp -v v3.8.0
2102 error gyp ERR! not ok 
2102 error Build failed with error code: 1
2103 verbose exit 1
2104 timing npm Completed in 53164ms
2105 verbose unfinished npm timer reify 1640746055969
2106 verbose unfinished npm timer reify:build 1640746094013
2107 verbose unfinished npm timer build 1640746094014
2108 verbose unfinished npm timer build:deps 1640746094014
2109 verbose unfinished npm timer build:run:postinstall 1640746099176
2110 verbose unfinished npm timer build:run:postinstall:node_modules/node-sass 1640746099176
2111 verbose code 1
2112 error A complete log of this run can be found in:
2112 error     C:\Users\Gary.Lu\AppData\Local\npm-cache\_logs\2021-12-29T02_47_34_408Z-debug-0.log

但是当我构建另一个使用Angular 12的项目时,我却没有遇到同样的错误。这是否重要,或者我错过了某些东西,不能在没有它的情况下构建?能否有人指导我解决这个问题?


你的代码是为Python 2设置的,但你只有Python 3。 - CertainPerformance
我已经安装了 Python 2.7.17,但没有任何效果。我能有更多解决方法吗? - Gary Lu
3
尝试将 Node 版本降级至 14.X。 - sojin
1
python2 添加到您的 PATH 中。 - CertainPerformance
2
@sojin 你的想法对我很有用!谢谢! - Gary Lu
5个回答

22

我也遇到了这个问题,我的解决方法如下:

1- npm卸载node-sass

2- 安装sass:npm i -D sass

3- 安装依赖包:npm i


我正在苦苦搜索“-D”选项的含义。它是什么? - andy4thehuynh
@andy4thehuynh 这是为了将依赖项安装为开发依赖项。 - undefined

0

0

node-sass需要特定的Node版本,您需要检查Node的版本是否与node-sass兼容。


0

通常这种情况是因为您的环境在运行npm install之后发生了变化。请运行npm rebuild node-sass以下载适用于您当前环境的绑定。

所以我运行了npm rebuild node-sass,然后它就起作用了!然后运行npm install,一切都顺利进行。


0
首先确定你的Sass中使用的Python版本和Node版本。 可以通过在包中搜索来找到Node版本,它会显示如下:
 "engines": {
  "node": ">=8.0.0"
}

对于绑定文件中的Python版本
'python': ['<3.10.0>'],

然后安装Node和Python的所需版本。
如果你已经安装了nvm,你可以使用以下命令:
nvm install @version_name

对于Python,你需要从Python官网下载所需的版本,然后将其值添加到系统变量中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接