NPM 相关命令,报错 node-gyp… 的解决方法

'node-gyp-build' is not recognized as an internal or external command, operable program or batch file.
npm ERR! gyp verb `which` failed Error: not found: python2

相关的异常信息

> node-gyp-build


                    errorOut='node-gyp-build' is not recognized as an internal or external command,
    operable program or batch file.
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! utf-8-validate@5.0.9 install: `node-gyp-build`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the utf-8-validate@5.0.9 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!     D:\app\nodejs\npm-cache\_logs\2022-06-10T00_53_04_766Z-debug.log

                    command='D:\app\nodejs\node.exe' 'D:\app\nvm\v14.7.0\node_modules\npm\bin\npm-cli.js' rebuild utf-8-validate@5.0.9
                    workingDir=
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lx-music-desktop@1.22.0-beta pack:dir: `node build-config/pack.js && electron-builder --dir`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the lx-music-desktop@1.22.0-beta pack:dir 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!     D:\app\nodejs\npm-cache\_logs\2022-06-10T00_53_04_842Z-debug.log

通用的解决方案

1. 在线安装,适合拥有纯净 Windows 开发环境的用户(没有安装过 Python, Visual Studio 等…)

# 全局设置淘宝镜像(配置过的老鸟可忽略此步骤)
$ npm config set registry https://registry.npm.taobao.org
# 单次使用淘宝镜像(会使用的老鸟可忽略此步骤)
$ npm install -g node-gyp --registry=https://registry.npm.taobao.org
$ npm install -g --production windows-build-tools --registry=https://registry.npm.taobao.org

2. 手动安装,针对拥有非纯净 Windows 开发环境的老鸟(安装过 Python, Visual Studio 等…)

重点注意: 等到 Starting installation... 命令字样出现后,立马 Ctrl C 终止后面的安装过程
!!! 因为我们必须自定义安装这两个新环境,才能不影响我们系统中已安装的 python 和 vs 等环境。

巧妙获取 python2 和 msvs_version 相关版本的安装包

$ npm install --global --production windows-build-tools
npm WARN deprecated windows-build-tools@5.2.2: Node.js now includes build tools for Windows. You probably no longer need this tool. See https://github.com/felixrieseberg/windows-build-tools for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

> windows-build-tools@5.2.2 postinstall D:\app\nodejs\node_global\node_modules\windows-build-tools
> node ./dist/index.js

Downloading python-2.7.15.amd64.msi
[============================================>] 100.0% of 20.2 MB (9 MB/s)
Downloaded python-2.7.15.amd64.msi. Saved to C:\Users\cpw\.windows-build-tools\python-2.7.15.amd64.msi.
Downloading vs_BuildTools.exe
[============================================>] 100.0% of 1.12 MB (1.12 MB/s)
Downloaded vs_BuildTools.exe. Saved to C:\Users\cpw\.windows-build-tools\vs_BuildTools.exe.

Starting installation...
Launched installers, now waiting for them to finish.
This will likely take some time - please be patient!

Status from the installers:
---------- Visual Studio Build Tools ----------
Still waiting for installer log file...
------------------- Python --------------------
Still waiting for installer log file...^C

手动安装 python2 和 msvs_version 到自定义目录

# 静默安装 python2 到指定的目录
Microsoft Windows [版本 10.0.19044.1706]
(c) Microsoft Corporation。保留所有权利。

C:\Users\cpw\.windows-build-tools>msiexec /a C:\Users\cpw\.windows-build-tools\python-2.7.15.amd64.msi /quiet TargetDir="C:/app/pvm/v2.7.15"
# 静默安装 vs_BuildTools 到默认的目录
C:\Users\cpw\.windows-build-tools>vs_BuildTools.exe /quiet PrependPath=0 Include_launcher=0 Include_test=0 Include_tcltk=0 Shortcuts=0

全局设置 python2 和 msvs_version 环境变量

# 全局设置 python2 环境变量
$ npm config set python2 "C:\Python27\python.exe"
# 全局设置 buildTools 环境变量
$ npm config set msvs_version "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools"

查看 NPM 全局配置

$ npm config list -g
; cli configs
global = true
metrics-registry = "https://registry.npm.taobao.org/"
scope = ""
user-agent = "npm/6.14.13 node/v14.17.0 win32 x64"

; userconfig C:\Users\cpw\.npmrc
CHROMEDRIVER_CDNURL = "https://npm.taobao.org/mirrors/chromedriver"
ELECTRON_BUILDER_BINARIES_MIRROR = "https://npm.taobao.org/mirrors/electron-builder-binaries/"
ELECTRON_MIRROR = "https://npm.taobao.org/mirrors/electron/"
NVM_NODEJS_ORG_MIRROR = "https://npm.taobao.org/mirrors/node"
OPERADRIVER = "https://npm.taobao.org/mirrors/operadriver"
PYTHON_MIRROR = "https://npm.taobao.org/mirrors/python"
cache = "D:\\app\\nodejs\\npm-cache"
chromedriver_cdnurl = "https://npm.taobao.org/mirrors/chromedriver"
electron-builder-binaries_mirror = "https://npm.taobao.org/mirrors/electron-builder-binaries/"
electron_mirror = "https://npm.taobao.org/mirrors/electron/"
msvs_version = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools"
node_sqlite3_binary_host_mirror = "http://npm.taobao.org/mirrors"
phantomjs_cdnurl = "https://npm.taobao.org/mirrors/phantomjs"
prefix = "D:\\app\\nodejs\\node_global"
python = "‪D:\\app\\pvm\\v2.7.15\\python.exe"
registry = "https://registry.npm.taobao.org/"
sass_binary_site = "https://npm.taobao.org/mirrors/node-sass/"
strict-ssl = false

; node bin location = D:\app\nodejs\node.exe
; cwd = D:\code\NodejsProjects\lx-music-desktop
; HOME = C:\Users\cpw
; "npm config ls -l" to show all defaults.

总结

到此这篇关于NPM相关命令之报错node-gyp...解决的文章就介绍到这了,更多相关NPM报错node-gyp...解决内容请搜索Devmax以前的文章或继续浏览下面的相关文章希望大家以后多多支持Devmax!

NPM相关命令之报错node-gyp...的解决方法的更多相关文章

  1. nodejs npm package.json中文文档

    这篇文章主要介绍了nodejs npm package.json中文文档,本文档中描述的很多行为都受npm-config(7)的影响,需要的朋友可以参考下

  2. 浅析Nodejs npm常用命令

    这篇文章主要介绍了浅析Nodejs npm常用命令的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下

  3. vue如何解决空格和空行报错的问题

    这篇文章主要介绍了vue如何解决空格和空行报错的问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  4. 基于Vue3实现前端埋点上报插件并打包发布到npm的详细过程

    这篇文章主要介绍了基于Vue3实现一个前端埋点上报插件并打包发布到npm,本项目采用pnpm进行Monorepo环境搭建,因为未来这个项目可能会加入更多的工具包,需要的朋友可以参考下

  5. 解决npm管理员身份install时出现权限的问题

    下面小编就为大家分享一篇解决npm管理员身份install时出现权限的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

  6. 解决Android studio 3.6.1 出现Cause: unable to find valid certification path to requested target 报错的问题

    这篇文章主要介绍了Android studio 3.6.1 出现Cause: unable to find valid certification path to requested target 报错的问题及解决方法,需要的朋友可以参考下

  7. 解决修复npm安装全局模块权限的问题

    今天小编就为大家分享一篇解决修复npm安装全局模块权限的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

  8. nodeJs的安装与npm全局环境变量的配置详解

    这篇文章主要介绍了nodeJs的安装与npm全局环境变量的配置详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  9. 详解Nodejs之npm&package.json

    本篇文章主要介绍了详解Nodejs之npm&package.json,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  10. Node.js的npm包管理器基础使用教程

    特别是JavaScript领域中,基于NPM的网络传输方式真的是越来越流行,包括React与Vue等许多JavaScript库与框架都选择使用npm进行管理,这里就为大家送上Node.js的npm包管理器基础使用教程,需要的朋友可以参考下

随机推荐

  1. Error: Cannot find module ‘node:util‘问题解决

    控制台 安装 Vue-Cli 最后一步出现 Error: Cannot find module 'node:util' 问题解决方案1.问题C:\Windows\System32>cnpm install -g @vue/cli@4.0.3internal/modules/cjs/loader.js:638 throw err; &nbs

  2. yarn的安装和使用(全网最详细)

    一、yarn的简介:Yarn是facebook发布的一款取代npm的包管理工具。二、yarn的特点:速度超快。Yarn 缓存了每个下载过的包,所以再次使用时无需重复下载。 同时利用并行下载以最大化资源利用率,因此安装速度更快。超级安全。在执行代码之前,Yarn 会通过算法校验每个安装包的完整性。超级可靠。使用详细、简洁的锁文件格式和明确的安装算法,Yarn 能够保证在不同系统上无差异的工作。三、y

  3. 前端环境 本机可切换node多版本 问题源头是node使用的高版本

    前言投降投降 重头再来 重装环境 也就分分钟的事 偏要折腾 这下好了1天了 还没折腾出来问题的源头是node 使用的高版本 方案那就用 本机可切换多版本最终问题是因为nodejs的版本太高,导致的node-sass不兼容问题,我的node是v16.14.0的版本,项目中用了"node-sass": "^4.7.2"版本,无法匹配当前的node版本根据文章的提

  4. nodejs模块学习之connect解析

    这篇文章主要介绍了nodejs模块学习之connect解析,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  5. nodejs npm package.json中文文档

    这篇文章主要介绍了nodejs npm package.json中文文档,本文档中描述的很多行为都受npm-config(7)的影响,需要的朋友可以参考下

  6. 详解koa2学习中使用 async 、await、promise解决异步的问题

    这篇文章主要介绍了详解koa2学习中使用 async 、await、promise解决异步的问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  7. Node.js编写爬虫的基本思路及抓取百度图片的实例分享

    这篇文章主要介绍了Node.js编写爬虫的基本思路及抓取百度图片的实例分享,其中作者提到了需要特别注意GBK转码的转码问题,需要的朋友可以参考下

  8. CentOS 8.2服务器上安装最新版Node.js的方法

    这篇文章主要介绍了CentOS 8.2服务器上安装最新版Node.js的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  9. node.js三个步骤实现一个服务器及Express包使用

    这篇文章主要介绍了node.js三个步骤实现一个服务器及Express包使用,文章通过新建一个文件展开全文内容,具有一定的参考价值,需要的小伙伴可以参考一下

  10. node下使用UglifyJS压缩合并JS文件的方法

    下面小编就为大家分享一篇node下使用UglifyJS压缩合并JS文件的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

返回
顶部