npm install报错:ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1

13,317次阅读
没有评论

共计 3923 个字符,预计需要花费 10 分钟才能阅读完成。

项目场景:

今天从 GitHub 上拉了一个 vue 前端项目,也就是人人开源的前端项目。在进行 npm install 的时候给我报了一大堆错误

D:Spring-Cloud-Platform-UI-dev>npm install
npm ERR! code CERT_HAS_EXPIRED
npm ERR! errno CERT_HAS_EXPIRED
npm ERR! request to https://registry.npm.taobao.org/@types/semver failed, reason: certificate has expired

npm ERR! A complete log of this run can be found in:
npm ERR!     C:UserslenovoAppDataRoamingnpm-cache_logs2024-07-26T01_13_03_869Z-debug.log

一开始,清理缓存,去官网看一下 node 和 npm 的对应版本是否正确,以下是 node 官网上 node 和 npm 的对应版本。

官网地址:
https://nodejs.org/zh-cn/download/releases

对应版本:
npm install 报错:ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1

试过了 如下办法

  1. 查看 npm 镜像设置
npm config get registry
  1. 将 npm 设置为淘宝镜像
npm config set registry https://registry.npm.taobao.org
  1. 再次查看 npm 镜像设置
npm config get registry
  1. 重新 install
npm install

后面又找了一下别人的解决方法:

  1. 第一步:解决方法如下:
npm cache clean --force
 npm config set registry https://mirrors.huaweicloud.com/repository/npm/

1、然后 运行 npm install 后报错如下:

gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable"python", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (D:Spring-Cloud-Platform-UI-devnode_modulesnode-gyplibconfigure.js:484:19)
gyp ERR! stack     at PythonFinder. (D:Spring-Cloud-Platform-UI-devnode_modulesnode-gyplibconfigure.js:509:16)
gyp ERR! stack     at D:Spring-Cloud-Platform-UI-devnode_modulesgraceful-fspolyfills.js:284:29
gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:183:21)
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "D:Program Filesnodejsnode.exe" "D:springProjectSpring-Cloud-Platform-UI-devnode_modulesnode-gypbinnode-gyp.js" "rebui
ld""--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:Spring-Cloud-Platform-UI-devnode_modulesnode-sass
gyp ERR! node -v v14.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modulesfsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":
"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.9.4 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.9.4 postinstall 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:UserslenovoAppDataRoamingnpm-cache_logs2024-07-26T01_26_18_216Z-debug.log

最后 发现是 node-sass 安装源的问题,运行如下:

npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass

2、然后 运行 npm install 后报错如下:

gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable"python", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (D:Spring-Cloud-Platform-UI-devnode_modulesnode-gyplibconfigure.js:484:19)
gyp ERR! stack     at PythonFinder. (D:Spring-Cloud-Platform-UI-devnode_modulesnode-gyplibconfigure.js:509:16)
gyp ERR! stack     at D:Spring-Cloud-Platform-UI-devnode_modulesgraceful-fspolyfills.js:284:29
gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:183:21)
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "D:Program Filesnodejsnode.exe" "D:springProjectSpring-Cloud-Platform-UI-devnode_modulesnode-gypbinnode-gyp.js" "rebui
ld""--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:Spring-Cloud-Platform-UI-devnode_modulesnode-sass
gyp ERR! node -v v14.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modulesfsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":
"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.9.4 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.9.4 postinstall 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:UserslenovoAppDataRoamingnpm-cache_logs2024-07-26T01_26_18_216Z-debug.log

3、仔细看了控制台报错,最后发现是因为缺了 node-sass 的包。

npm install node-sass

搞定,完结,撒花!

原文地址: npm install 报错:ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于2024-11-04发表,共计3923字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)