错误 "sh: node-gyp-build: command not found"

4

npm install 安装失败,出现以下错误信息。我尝试删除 node_modules 文件夹并重新安装,但没有成功:

15104 错误命令 sh -c node-gyp-build

15105 错误 sh: node-gyp-build: 未找到命令

我该如何解决这个问题?

npm install --verbose 的错误日志:

npm ERR! code 127
npm ERR! path /Users/johnnycheng/Documents/React Projects/blockchain:fintech/coin-web-test2/node_modules/utf-8-validate
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! sh: node-gyp-build: command not found
npm verb exit 127
npm timing npm Completed in 30755ms
npm verb unfinished npm timer reify 1650620386080
npm verb unfinished npm timer reify:build 1650620407577
npm verb unfinished npm timer build 1650620407582
npm verb unfinished npm timer build:deps 1650620407583
npm verb unfinished npm timer build:run:install 1650620407669
npm verb unfinished npm timer build:run:install:node_modules/bufferutil 1650620407670
npm verb unfinished npm timer build:run:install:node_modules/utf-8-validate 1650620407692
npm verb code 127

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/johnnycheng/.npm/_logs/2022-04-22T09_39_45_773Z-debug-0.log

我的项目中的文件package.json

{
  "name": "coin-web-test2",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.9.0",
    "@emotion/styled": "^11.8.1",
    "@fontsource/roboto": "^4.5.5",
    "@mui/material": "^5.6.2",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^13.2.1",
    "crypto-js": "^3.1.9-1",
    "ethers": "^5.6.4",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-router-dom": "^6.3.0",
    "react-scripts": "4.0.3",
    "web-vitals": "^2.1.0",
    "web3": "^1.7.3"
  },
  "scripts": {
    "start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

在此处查看完整的错误日志:完整错误日志

环境:macOS v12.3.1(蒙特雷)

Node.js 版本:16.14.2

npm 版本:8.7.0


你正在使用哪个操作系统环境来完成这个? - yue you
macOS Monterey 12.3.1 - jonijeng
4个回答

3

请尝试使用以下命令进行安装:

npm install node-gyp

3
在我的Dockerfile中添加了全局安装的node-gyp。
FROM node:18-alpine
# Installing libvips-dev for sharp Compatibility
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev yarn
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}

RUN npm install -g node-gyp

帮助我在node-18:alpine上运行Strapi 4.14.4的docker设置。
希望对其他正在谷歌这个随机的问题的人有所帮助。

2
运行 yarn install 然后运行 npm install 会奇妙地起作用。 我不知道为什么。

你的锁定文件只有在yarn中吗? - yue you
这个解决方案对我也有帮助:先运行 yarn install,然后再运行 npm install。 - SimonZ89

2

我发现你的package.json文件中没有node-gyp模块。
试着运行npm install node-gyp并按照npm链接node-gyp模块的说明进行操作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接