如何解决 Mac 上的 npm 安装错误

Chr*_*ris 9 npm-install

我在线购买了 Gatsby JS 网站的模板,当我尝试使用它时,它起作用了,但随后就停止了。我尝试在新目录中打开该项目,但失败了。

目前我无法运行npm install该项目,也不知道如何解决该问题。

错误消息是:

    npm ERR! code 1
    npm ERR! path /Users/chistopherholder/Desktop/react_play/rewy-gatsby-with-strapi/rewy-api/node_modules/sharp
    npm ERR! command failed
    npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
    npm ERR! info sharp Using cached /Users/chistopherholder/.npm/_libvips/libvips-8.10.0-darwin-x64.tar.br
    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.15.5 | darwin | x64
    npm ERR! gyp info spawn /usr/bin/python2
    npm ERR! gyp info spawn args [
    npm ERR! gyp info spawn args   '/Users/chistopherholder/Desktop/react_play/rewy-gatsby-with-strapi/rewy-api/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/chistopherholder/Desktop/react_play/rewy-gatsby-with-strapi/rewy-api/node_modules/sharp/build/config.gypi',
    npm ERR! gyp info spawn args   '-I',
    npm ERR! gyp info spawn args   '/Users/chistopherholder/Desktop/react_play/rewy-gatsby-with-strapi/rewy-api/node_modules/node-gyp/addon.gypi',
    npm ERR! gyp info spawn args   '-I',
    npm ERR! gyp info spawn args   '/Users/chistopherholder/.node-gyp/14.15.5/include/node/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=/Users/chistopherholder/.node-gyp/14.15.5',
    npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/chistopherholder/Desktop/react_play/rewy-gatsby-with-strapi/rewy-api/node_modules/node-gyp',
    npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/chistopherholder/.node-gyp/14.15.5/<(target_arch)/node.lib',
    npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/chistopherholder/Desktop/react_play/rewy-gatsby-with-strapi/rewy-api/node_modules/sharp',
    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! No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
    npm ERR! 
    npm ERR! No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.
    npm ERR! 
    npm ERR! No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.
    npm ERR! 
    npm ERR! gyp: No Xcode or CLT version detected!
    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/chistopherholder/Desktop/react_play/rewy-gatsby-with-strapi/rewy-api/node_modules/node-gyp/lib/configure.js:345:16)
    npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
    npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
    npm ERR! gyp ERR! System Darwin 20.3.0
    npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/chistopherholder/Desktop/react_play/rewy-gatsby-with-strapi/rewy-api/node_modules/.bin/node-gyp" "rebuild"
    npm ERR! gyp ERR! cwd /Users/chistopherholder/Desktop/react_play/rewy-gatsby-with-strapi/rewy-api/node_modules/sharp
    npm ERR! gyp ERR! node -v v14.15.5
    npm ERR! gyp ERR! node-gyp -v v3.8.0
    npm ERR! gyp ERR! not ok

    npm ERR! A complete log of this run can be found in:
    npm ERR!     /Users/chistopherholder/.npm/_logs/2021-03-05T00_04_39_680Z-debug.log
Run Code Online (Sandbox Code Playgroud)

我打开了debug.log,但里面有1787行代码,我不太明白。我也尝试过sudo npm install

我该如何解决这些问题?

任何正确方向的暗示将不胜感激。我通常使用 django 并且没有反应,所以我在这里有点无能为力。

epe*_*per 12

在每种情况下可能都不是同样的问题,但每当我看到npm ERR! gyp: No Xcode or CLT version detected!我必须删除 xcode 并重新安装时,错误就会消失。我最好的猜测是,这是 Node 和/或 MacO 更新的问题,导致了冲突。

出现这种情况你可以先尝试:

sudo xcode-select --reset
Run Code Online (Sandbox Code Playgroud)

如果这不起作用(对我来说从来没有)你可以尝试:

sudo rm -rf $(xcode-select -print-path) && xcode-select --install
Run Code Online (Sandbox Code Playgroud)