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

相关文章

  • Node.js利用debug模块打印出调试日志的方法

    Node.js利用debug模块打印出调试日志的方法

    debug日志打印模块主要实现功能是带命名空间(模块名)、时间戳、色彩输出日志;将日志写入文件;浏览器端使用;格式化函数;支持自定义方法。下面这篇文章主要介绍了Node.js利用debug模块打印出调试日志的方法,需要的朋友可以参考借鉴,下面来一起看看吧。
    2017-04-04
  • koa2上传文件及https配置实现教程

    koa2上传文件及https配置实现教程

    这篇文章主要为大家介绍了koa2上传文件及https配置实现教程详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-06-06
  • 详细谈谈NodeJS进程是如何退出的

    详细谈谈NodeJS进程是如何退出的

    这篇文章主要给大家介绍了关于NodeJS进程是如何退出的相关资料,主要介绍了导致进程退出的三个因素:主动退出;未捕获的异常、未处理的 promise rejection;未处理的 Event Emitter error 事件 系统信号,需要的朋友可以参考下
    2021-07-07
  • package.json的版本号更新优化方法

    package.json的版本号更新优化方法

    这篇文章主要为大家介绍了package.json的版本号更新优化方法详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-04-04
  • Node.js中使用mongoose操作mongodb数据库的方法

    Node.js中使用mongoose操作mongodb数据库的方法

    如何利用mongoose将数据写入mongodb数据库呢?操作方法很简单,下面小编给大家分享Node.js中使用mongoose操作mongodb数据库的方法,感兴趣的朋友一起看看吧
    2017-09-09
  • node.js中的fs.chmodSync方法使用说明

    node.js中的fs.chmodSync方法使用说明

    这篇文章主要介绍了node.js中的fs.chmodSync方法使用说明,本文介绍了fs.chmodSync方法说明、语法、接收参数、使用实例和实现源码,需要的朋友可以参考下
    2014-12-12
  • node.js核心模块有哪些

    node.js核心模块有哪些

    这篇文章主要介绍了node.js核心模块有哪些,对node.js感兴趣的同学,可以参考下
    2021-04-04
  • 使用express+multer实现node中的图片上传功能

    使用express+multer实现node中的图片上传功能

    这篇文章主要介绍了使用express+multer实现node中的图片上传功能,需要的朋友可以参考下
    2018-02-02
  • Node.js API详解之 tty功能与用法实例分析

    Node.js API详解之 tty功能与用法实例分析

    这篇文章主要介绍了Node.js API详解之 tty功能与用法,结合实例形式分析了Node.js API中tty的基本功能、用法及终端操作相关使用技巧,需要的朋友可以参考下
    2020-04-04
  • 如何在Nestjs和Vue3中使用socket.io示例详解

    如何在Nestjs和Vue3中使用socket.io示例详解

    这篇文章主要为大家介绍了如何在Nestjs和Vue3中使用socket.io示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-08-08

最新评论