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

 更新时间:2022年09月05日 13:06:01   作者:班纳  
node-gyp就是为node编译c++扩展的时候使用的编译工具,下面这篇文章主要给大家介绍了关于NPM相关命令之报错node-gyp...的解决方法,文中通过实例代码介绍的非常详细,需要的朋友可以参考下

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...解决内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • nodejs爬虫初试superagent和cheerio

    nodejs爬虫初试superagent和cheerio

    这篇文章主要介绍了nodejs爬虫初试superagent和cheerio的相关知识,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2018-03-03
  • 基于模板引擎Jade的应用(详解)

    基于模板引擎Jade的应用(详解)

    下面小编就为大家分享一篇基于模板引擎Jade的应用详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2017-12-12
  • node.js基于dgram数据报模块创建UDP服务器和客户端操作示例

    node.js基于dgram数据报模块创建UDP服务器和客户端操作示例

    这篇文章主要介绍了node.js基于dgram数据报模块创建UDP服务器和客户端操作,结合实例形式分析了node.js使用dgram数据报模块创建UDP服务器和客户端,以及进行UDP广播、组播相关操作技巧,需要的朋友可以参考下
    2020-02-02
  • node.js中stream流中可读流和可写流的实现与使用方法实例分析

    node.js中stream流中可读流和可写流的实现与使用方法实例分析

    这篇文章主要介绍了node.js中stream流中可读流和可写流的实现与使用方法,结合实例形式分析了node.js stream流可读流和可写流基本分类、原理、定义、使用方法及相关注意事项,需要的朋友可以参考下
    2020-02-02
  • 从零学习node.js之简易的网络爬虫(四)

    从零学习node.js之简易的网络爬虫(四)

    简单的爬虫实现原理很简单:发送http请求至目标地址获取HTML页面数据,然后从获取来的页面数据中提取需要的数据保存。下面这篇文章主要介绍了利用node.js实现简易的网络爬虫的相关资料,需要的朋友可以参考下。
    2017-02-02
  • 使用 Node.js 实现图片的动态裁切及算法实例代码详解

    使用 Node.js 实现图片的动态裁切及算法实例代码详解

    这篇文章主要介绍了使用 Node.js 实现图片的动态裁切功能,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-09-09
  • 使用GruntJS构建Web程序之合并压缩篇

    使用GruntJS构建Web程序之合并压缩篇

    前一篇讲述了如何使用concat和uglify命令实现JavaScript资源的合并,压缩。这篇讲述下css资源的合并和压缩。
    2014-06-06
  • Node.js fs模块原理及常见用途

    Node.js fs模块原理及常见用途

    这篇文章主要介绍了Node.js fs模块原理及常见用途,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-10-10
  • 使用NODE.JS创建一个WEBSERVER(服务器)的步骤

    使用NODE.JS创建一个WEBSERVER(服务器)的步骤

    在 node.js 中创建一个服务器非常简单,只需要使用 node.js 为我们提供的 http 模块及相关 API 即可创建一个麻雀虽小但五脏俱全的web 服务器,相比 Java/Python/Ruby 搭建web服务器的过程简单的很。本文简单的讲解下实现步骤
    2021-06-06
  • ubuntu下安装nodejs以及升级的办法

    ubuntu下安装nodejs以及升级的办法

    本文介绍了ubuntu 12.04服务器安装nodejs以及升级的方法,ubuntu安装nodejs以及升级的实例教程,需要的朋友参考下。
    2015-05-05

最新评论