npm install 报错 gyp info it worked if it ends with ok npm ERR! gyp verb cli [

今天新启动一个项目,在 npm install 安装依赖项时出现报错。

ERR! code 1
npm ERR! path C:\Users\Administrator\Desktop\14531\mall-admin-web\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 C:\Users\Administrator\Desktop\14531\mall-admin-web\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   'C:\\Program Files\\nodejs\\node.exe',
npm ERR! gyp verb cli   'C:\\Users\\Administrator\\Desktop\\14531\\mall-admin-web\\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@14.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 (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183: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 (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! gyp verb `which` failed  python Error: not found: python
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183: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 (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\node-gyp\lib\configure.js:484:19)
npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\node-gyp\lib\configure.js:509:16)
npm ERR! gyp ERR! stack     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\graceful-fs\polyfills.js:284:29
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! gyp ERR! System Windows_NT 10.0.19041
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Administrator\\Desktop\\14531\\mall-admin-web\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\node-sass
npm ERR! gyp ERR! node -v v14.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\Administrator\AppData\Local\npm-cache\_logs\2021-04-06T07_35_56_176Z-debug.log
PS C:\Users\Administrator\Desktop\14531\mall-admin-web> npm install npm -g

removed 218 packages, and changed 3 packages in 7s
PS C:\Users\Administrator\Desktop\14531\mall-admin-web> npm install
npm ERR! code 1
npm ERR! path C:\Users\Administrator\Desktop\14531\mall-admin-web\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 C:\Users\Administrator\Desktop\14531\mall-admin-web\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   'C:\\Program Files\\nodejs\\node.exe',
npm ERR! gyp verb cli   'C:\\Users\\Administrator\\Desktop\\14531\\mall-admin-web\\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@14.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 (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183: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 (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! gyp verb `which` failed  python Error: not found: python
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183: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 (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\node-gyp\lib\configure.js:484:19)
npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\node-gyp\lib\configure.js:509:16)
npm ERR! gyp ERR! stack     at C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\graceful-fs\polyfills.js:284:29
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! gyp ERR! System Windows_NT 10.0.19041
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Administrator\\Desktop\\14531\\mall-admin-web\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd C:\Users\Administrator\Desktop\14531\mall-admin-web\node_modules\node-sass
npm ERR! gyp ERR! node -v v14.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\Administrator\AppData\Local\npm-cache\_logs\2021-04-06T07_40_11_291Z-debug.log

解决方案

npm install -g mirror-config-china --registry=http://registry.npm.taobao.org
npm install node-sass
npm install

<think>好的,我现在需要帮助用户解决在Windows系统中使用Node.js 16.14.2时遇到的node-gyp报错,特别是Python路径配置问题以及命令分隔符错误。首先,我需要回顾用户提供的引用信息和之前的对话历史,确保解决方案全面且准确。 用户提到了几个引用,其中引用[1]、[2]、[3]、[4]、[5]都涉及node-sass安装失败、node-gyp构建错误以及命令分隔符的问题。特别是引用[2]和[4]显示在Windows环境下使用cmd执行命令时出现错误,包括node-gyp rebuild失败和命令分隔符问题。用户现在的问题集中在Python路径配置和&&分隔符无效上,需要针对这两个方面给出解决方案。 首先,处理Python配置问题。node-gyp需要Python 2.7或3.x版本,但用户可能未安装或路径未正确设置。Windows下常见的解决方法是安装Python并添加到系统路径,同时设置npm的Python配置。此外,用户可能安装了多个Python版本,需要指定正确的版本给npm。 其次,命令分隔符错误。用户在PowerShell中使用了&&,但PowerShell默认使用分号或换行来分隔命令,而&&是CMD的语法。因此,用户需要调整命令的执行方式,比如使用分号、换行,或者改用CMD环境来运行这些命令。 接下来,我需要整合之前的回答中的解决方案。之前的回答提到安装Xcode工具、更新Python、清理npm缓存、使用nvm管理Node版本等,但这些主要针对macOS。现在需要调整为Windows环境下的解决方法,比如安装Python、设置路径、配置npm的Python路径,以及处理PowerShell命令分隔符的问题。 此外,用户可能未安装构建工具,如Visual Studio Build Tools,其中包含C++编译器等必要组件。这也是node-gyp在Windows上常见的问题,需要检查并安装。 需要确保步骤清晰,分点说明,每个问题单独处理。例如,Python路径配置部分需要安装Python,设置环境变量,配置npm的python路径。命令分隔符错误则需要解释PowerShell与CMD的区别,并提供替代命令或切换shell的方法。 最后,验证步骤很重要,确保用户按照步骤操作后问题得到解决。可能需要建议用户安装特定版本的Python,或者使用管理员权限运行命令,避免权限问题。 总结,解决方案应包括: 1. 安装Python并配置路径。 2. 安装Visual Studio Build Tools。 3. 配置npm的Python和MSVS版本。 4. 处理命令分隔符错误,调整命令语法或切换shell。 5. 清理缓存并重试安装。 6. 验证安装和配置是否成功。 需要确保每一步都详细,命令正确,并给出可能的备选方案,比如使用管理员权限或不同的命令提示符。同时,参考用户提供的引用中的解决方案,如更新node-sass版本,但这里主要关注Python和命令分隔符问题。</think>### 解决方案:Windows 下 Node.js 16.14.2 的 Python 配置与 `&&` 命令分隔符问题 --- #### **问题一:`gyp info it worked if it ends with ok` 报错(Python 路径配置问题)** 此错误通常由以下原因导致: 1. **Python 未安装或路径未正确配置** node-gyp 需要 Python 2.7 或 3.x 环境,且需通过系统环境变量或 npm 配置指定路径。 2. **缺少构建工具链** Windows 下需安装 Visual Studio Build Tools 以支持 C++ 扩展编译。 **分步解决:** 1. **安装 Python 并配置路径** - 从 [Python 官网](https://www.python.org/downloads/windows/) 下载 Python 3.9+(建议勾选 `Add Python to PATH`)。 - 验证安装: ```bash python --version # 应显示 Python 3.x.x ``` - 通过 npm 指定 Python 路径: ```bash npm config set python "C:\Python39\python.exe" # 替换为实际安装路径 ``` 2. **安装 Visual Studio Build Tools** - 下载并安装 [Build Tools for Visual Studio 2022](https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/),勾选以下组件: - “C++ 生成工具” - “Windows 10 SDK”(根据系统版本选择) - 配置 npm 使用的 MSVS 版本: ```bash npm config set msvs_version 2022 # 与安装的 VS 版本一致 ``` 3. **清理并重试安装** ```bash npm cache clean --force npm uninstall node-sass # 如果涉及 node-sass npm install --global windows-build-tools # 可选,自动安装 Python 和 VS Build Tools npm install # 重新安装依赖 ``` --- #### **问题二:`&&` 命令分隔符无效错误** Windows 系统中,`&&` 是 CMD 的命令分隔符,而 PowerShell 默认使用 `;` 或换行分隔。若在 PowerShell 中执行 `nvm uninstall 16.14.2 && nvm install 14.19.1`,会因语法不兼容报错。 **分步解决:** 1. **方法一:改用 CMD 执行命令** - 打开命令提示符(CMD): ```bash nvm uninstall 16.14.2 nvm install 14.19.1 ``` 2. **方法二:PowerShell 中分步执行** - 逐行执行命令: ```bash nvm uninstall 16.14.2 nvm install 14.19.1 ``` 3. **方法三:强制 PowerShell 兼容 CMD 语法** - 使用 `cmd /c` 包裹命令: ```bash cmd /c "nvm uninstall 16.14.2 && nvm install 14.19.1" ``` --- #### **验证环境配置** 1. 检查 Python 和 MSVS 配置: ```bash npm config get python # 应返回正确路径 npm config get msvs_version # 应返回 2015/2017/2019/2022 ``` 2. 测试 node-gyp 编译: ```bash npm install node-gyp -g node-gyp configure # 应输出成功日志 ``` --- #### **补充:node-sass 兼容性问题** 如果涉及 `node-sass` 报错(如引用 [1][3][4]): 1. 升级至兼容版本: ```bash npm uninstall node-sass npm install sass # 官方推荐替代品 ``` 2. 或指定 node-sass 版本: ```bash npm install node-sass@6.0.1 --save-dev # 兼容 Node.js 16.x ``` --- ### 总结命令示例 ```bash # 配置 Python 路径 npm config set python "C:\Python39\python.exe" # 安装构建工具(CMD 中执行) npm install --global windows-build-tools # 切换至 CMD 执行 nvm 命令 nvm uninstall 16.14.2 nvm install 14.19.1 nvm use 14.19.1 # 重新安装依赖 npm cache clean --force npm install ``` --- ### 相关问题 1. 如何在 Windows 中永久设置环境变量? 2. 如何解决 Node.js 版本与项目依赖不兼容的问题? 3. 为什么某些 npm 包需要本地编译(如 node-sass)?
评论 35
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值