一、问题
我遇到的报错是node-sass包的问题,这个包要求本地环境使用python2.7,但是我的版本是python3。
报错信息如下:
npm error code 1
npm error path D:\project\renren-test\renren-ui\node_modules\node-sass
npm error command failed
npm error command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js
npm error Building: D:\nvm4w\nodejs\node.exe D:\project\renren-test\renren-ui\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm error gyp info it worked if it ends with ok
npm error gyp verb cli [
npm error gyp verb cli 'D:\\nvm4w\\nodejs\\node.exe',
npm error gyp verb cli 'D:\\project\\renren-test\\renren-ui\\node_modules\\node-gyp\\bin\\node-gyp.js',
npm error gyp verb cli 'rebuild',
npm error gyp verb cli '--verbose',
npm error gyp verb cli '--libsass_ext=',
npm error gyp verb cli '--libsass_cflags=',
npm error gyp verb cli '--libsass_ldflags=',
npm error gyp verb cli '--libsass_library='
npm error gyp verb cli ]
npm error gyp info using node-gyp@3.8.0
npm error gyp info using node@25.2.1 | win32 | x64
npm error gyp verb command rebuild []
npm error gyp verb command clean []
npm error gyp verb clean removing "build" directory
npm error gyp verb command configure []
npm error gyp verb check python checking for Python executable "python2" in the PATH
npm error gyp verb `which` failed Error: not found: python2
npm error gyp verb `which` failed at getNotFoundError (D:\project\renren-test\renren-ui\node_modules\which\which.js:13:12)
npm error gyp verb `which` failed at F (D:\project\renren-test\renren-ui\node_modules\which\which.js:68:19)
npm error gyp verb `which` failed at E (D:\project\renren-test\renren-ui\node_modules\which\which.js:80:29)
npm error gyp verb `which` failed at D:\project\renren-test\renren-ui\node_modules\which\which.js:89:16
npm error gyp verb `which` failed at D:\project\renren-test\renren-ui\node_modules\isexe\index.js:42:5
npm error gyp verb `which` failed at D:\project\renren-test\renren-ui\node_modules\isexe\windows.js:36:5
npm error gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:190:21)
npm error gyp verb `which` failed python2 Error: not found: python2
npm error gyp verb `which` failed at getNotFoundError (D:\project\renren-test\renren-ui\node_modules\which\which.js:13:12)
npm error gyp verb `which` failed at F (D:\project\renren-test\renren-ui\node_modules\which\which.js:68:19)
npm error gyp verb `which` failed at E (D:\project\renren-test\renren-ui\node_modules\which\which.js:80:29)
npm error gyp verb `which` failed at D:\project\renren-test\renren-ui\node_modules\which\which.js:89:16
npm error gyp verb `which` failed at D:\project\renren-test\renren-ui\node_modules\isexe\index.js:42:5
npm error gyp verb `which` failed at D:\project\renren-test\renren-ui\node_modules\isexe\windows.js:36:5
npm error gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:190:21) {
npm error gyp verb `which` failed code: 'ENOENT'
npm error gyp verb `which` failed }
npm error gyp verb check python checking for Python executable "python" in the PATH
npm error gyp verb `which` succeeded python C:\Users\Lenovo\AppData\Local\Programs\Python\Python312\python.EXE
npm error (node:37480) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead.
npm error (Use `node --trace-deprecation ...` to show where the warning was created)
npm error gyp ERR! configure error
npm error gyp ERR! stack Error: Command failed: C:\Users\Lenovo\AppData\Local\Programs\Python\Python312\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
npm error gyp ERR! stack File "<string>", line 1
npm error gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
npm error gyp ERR! stack ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
npm error gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
npm error gyp ERR! stack
npm error gyp ERR! stack at genericNodeError (node:internal/errors:998:15)
npm error gyp ERR! stack at wrappedFn (node:internal/errors:543:14)
npm error gyp ERR! stack at ChildProcess.exithandler (node:child_process:417:12)
npm error gyp ERR! stack at ChildProcess.emit (node:events:508:28)
npm error gyp ERR! stack at maybeClose (node:internal/child_process:1085:16)
npm error gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:304:5)
npm error gyp ERR! System Windows_NT 10.0.26200
npm error gyp ERR! command "D:\\nvm4w\\nodejs\\node.exe" "D:\\project\\renren-test\\renren-ui\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm error gyp ERR! cwd D:\project\renren-test\renren-ui\node_modules\node-sass
npm error gyp ERR! node -v v25.2.1
npm error gyp ERR! node-gyp -v v3.8.0
npm error gyp ERR! not ok
npm error Build failed with error code: 1
npm error A complete log of this run can be found in: D:\nodejs\node_cache\_logs\2025-11-23T08_43_31_544Z-debug-0.log
讲真python2太老了我不想安装,因此我折腾了五六个小时才彻底解决这个问题。
二、我的解决方法
首先版本选择上使用14.21.3,我查到的资料中很多人都是在这个版本上成功的,建议直接用这个版本,少走弯路!!
在下载nodejs的时候我也用过nvm,但是我用它下载低版本的时候npm会出现下载失败的情况,因此我抛弃了nvm。
接下来是最关键的一步!!在报错后使用一下命令单独安装node-sass。
npm install node-sass@npm:sass --ignore-scripts
这个命令是安装一个包名是 node-sass,但它的实际内容是 sass的文件,sass可以理解为一个高版本的node-sass的一个替代品。
这个命令在一些nodejs版本可能会失败,因此建议使用上述的版本。
三、结果
输入npm run serve运行项目,倒腾了好久,看见运行成功真的泪目了o(╥﹏╥)o

希望这篇文章可以对你有帮助,我也是翻了好久的帖子才解决的问题。
关键帮助网站
https://gitee.com/renrenio/renren-fast-vue/issues/ICGJ6N
安装nodejs方法
卸载nodejs