首页 > 解决方案 > 当 npm install 我得到“错误:`gyp` failed with exit code”

问题描述

我使用 MacBook Air M1,我无法让我自己的代码从以前的 MacBook(MBP 2011 年末)工作。

我试过了:

即使我npm install <specific package>在安装完所有东西后仍然使用它,我得到了下面的东西。

npm ERR! code 1
npm ERR! path /Users/js/Developer/ac/node_modules/iconv
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@14.18.1 | darwin | x64
npm ERR! gyp info spawn /usr/local/bin/python2
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/Users/js/Developer/ac/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/js/Developer/ac/node_modules/iconv/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/js/Developer/ac/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/local/bin/node/src/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/usr/local/bin/node/src/',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/js/Developer/ac/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/usr/local/bin/node/src/$(Configuration)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/js/Developer/ac/node_modules/iconv',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp: /usr/local/bin/node/src/common.gypi not found (cwd: /Users/js/Developer/ac/node_modules/iconv) while reading includes of binding.gyp while trying to load binding.gyp
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/Users/js/Developer/ac/node_modules/node-gyp/lib/configure.js:345:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:282:12)
npm ERR! gyp ERR! System Darwin 20.6.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/js/Developer/ac/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/js/Developer/ac/node_modules/iconv
npm ERR! gyp ERR! node -v v14.18.1
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok

包.json

{
  "name": "ac",
  "version": "1.0.0",
  "description": "A Vue.js project",
  "author": "me",
  "private": true,
  "scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "build": "node build/build.js && firebase deploy",
    "functions-deploy": "firebase deploy --only functions",
    "functions-emulator": "firebase emulators:start --only functions"
  },
  "dependencies": {
    "angular-expressions": "^1.0.0",
    "axios": "^0.19.2",
    "bootstrap-vue": "^2.7.0",
    "cookie-parser": "^1.4.4",
    "docxtemplater": "^3.17.4",
    "file-saver": "^1.3.8",
    "firebase": "^6.2.4",
    "firebase-admin": "^8.9.2",
    "firebase-functions": "^3.0.2",
    "iconv": "^2.3.4",
    "jszip": "^2.6.1",
    "jszip-utils": "0.0.2",
    "node-sass": "^4.9.3",
    "pdffiller": "0.0.11",
    "pizzip": "^3.0.6",
    "pug-plain-loader": "^1.0.0",
    "sass-loader": "^7.1.0",
    "vue": "^2.6.11",
    "vue-multiselect": "^2.1.3"
  },
  "devDependencies": {
    "autoprefixer": "^7.1.2",
    "babel-core": "^6.22.1",
    "babel-helper-vue-jsx-merge-props": "^2.0.3",
    "babel-loader": "^7.1.1",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-plugin-transform-vue-jsx": "^3.5.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-stage-2": "^6.22.0",
    "chalk": "^2.0.1",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.0",
    "eslint": "^6.8.0",
    "eslint-config-standard": "^14.1.1",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.1",
    "eslint-plugin-vue": "^6.2.2",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^1.1.4",
    "friendly-errors-webpack-plugin": "^1.6.1",
    "html-webpack-plugin": "^2.30.1",
    "node-notifier": "^5.1.2",
    "optimize-css-assets-webpack-plugin": "^3.2.0",
    "ora": "^1.2.0",
    "portfinder": "^1.0.13",
    "postcss-import": "^11.0.0",
    "postcss-loader": "^2.0.8",
    "postcss-url": "^7.2.1",
    "pug": "^2.0.3",
    "pug-loader": "^2.4.0",
    "rimraf": "^2.6.0",
    "semver": "^5.3.0",
    "shelljs": "^0.7.6",
    "uglifyjs-webpack-plugin": "^1.1.1",
    "url-loader": "^0.5.8",
    "vue-loader": "^15.9.1",
    "vue-style-loader": "^3.0.1",
    "vue-template-compiler": "^2.6.11",
    "webpack": "^3.6.0",
    "webpack-bundle-analyzer": "^2.9.0",
    "webpack-dev-server": "^2.9.1",
    "webpack-merge": "^4.1.0"
  },
  "engines": {
    "node": ">= 6.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

标签: node.jsnpmnpm-install

解决方案


推荐阅读