记录一次npm install报错

本文解决了一个npm安装过程中遇到的问题,具体表现为使用node-gyp重建模块时出现Python语法错误。通过安装特定版本的Python和其他依赖工具,最终成功解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

报错信息:

gyp ERR! stack Error: Command failed: C:\Users\liufei\AppData\Local\Programs\Python\Python37\python.EXE -c import sys; print “%s.%s.%s” %

完整报错:

F:\webstorm\cloud-desktop> npm install
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.

> xxhash-addon@1.4.0 install F:\webstorm\cloud-desktop\node_modules\xxhash-addon
> node-gyp rebuild --ensure


F:\webstorm\cloud-desktop\node_modules\xxhash-addon>if not defined npm_config_node_gyp (node "E:\node\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild --ensure )  else (node "E:\node\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild --ensure )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\liufei\AppData\Local\Programs\Python\Python37\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:982:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "E:\\node\\node.exe" "E:\\node\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--ensure"
gyp ERR! cwd F:\webstorm\cloud-desktop\node_modules\xxhash-addon
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN @babel/plugin-syntax-jsx@7.14.5 requires a peer of @babel/core@^7.0.0-0 but none is installed. You must install peer dependencies yourself.
npm WARN @vue/babel-plugin-transform-vue-jsx@1.2.1 requires a peer of @babel/core@^7.0.0-0 but none is installed. You must install peer dependencies yourself.
npm WARN cloud-desktop@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! xxhash-addon@1.4.0 install: `node-gyp rebuild --ensure`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the xxhash-addon@1.4.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\liufei\AppData\Roaming\npm-cache\_logs\2021-06-10T02_12_29_752Z-debug.log

解决办法

步骤一

npm install --global --production windows-build-tools
npm install -g node-gyp

如果执行第一句执行没有成功,例如我的:
执行失败
这里卡在安装python了,直接终止执行步骤二即可。

步骤二

上面步骤一如果没有安装好python2.7,则安装下

npm install --python=python2.7

npm config set python python2.7

步骤三

npm install

npm run dev

启动成功!!

参考
https://blog.youkuaiyun.com/qfxlw/article/details/85331869

### 解决方案 当在 Git 项目中运行 `npm install` 遇到错误时,可以尝试多种方法来解决问题。以下是几种常见的解决方案: #### 方法一:配置全局 URL 替代 有时由于网络原因或其他因素,可能会导致无法正常访问某些资源。可以通过修改 Git 的全局配置文件来替代默认的协议。 ```bash git config --global url."https://".insteadOf git:// ``` 这一步骤有助于解决因协议不兼容引起的问题[^1]。 #### 方法二:处理未安装的 Git 工具 如果开发环境中缺少必要的版本控制系统工具(如 Git),则可能导致依赖项获取失败。对于这种情况,在 WebStorm 中启用并安装 Git 是一种有效的办法。 打开 WebStorm 菜单栏中的 **VCS** -> **Enable Version Control Integration...**, 然后点击提示框里的 “Download and Install”,完成 Git 安装后再试一次命令。确保 IDE 和终端环境一致也很重要[^2]。 #### 方法三:强制安装或忽略对等依赖关系警告 有时候包管理器会对特定版本之间的匹配度发出警告甚至阻止继续操作。此时可以选择强行覆盖这些约束条件来进行安装。 ```bash npm install --force # 或者 npm install --legacy-peer-deps ``` 这两种方式都可以帮助绕过一些不必要的冲突检查,从而顺利完成安装过程[^3]。 #### 方法四:清理 NPM 缓存及调整 SSL 设置 为了防止旧数据干扰新请求,建议先清除现有的缓存记录;另外适当放宽安全策略也有助于提高成功率。 ```bash npm cache clean --force npm config set strict-ssl false npm install ``` 通过上述措施能够有效减少由证书验证等问题引发的异常情况发生几率[^4]。 以上就是针对不同场景下的几条建议路径,可以根据实际情况灵活选用最合适的那一条或多条组合起来使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值