在mac下使用npm安装包的时候,老是报这个错误,具体信息如下:

node-gyp rebuild

No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/Users/sobird/.nvm/versions/node/v8.12.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Darwin 19.3.0
gyp ERR! command "/Users/sobird/.nvm/versions/node/v8.12.0/bin/node" "/Users/sobird/.nvm/versions/node/v8.12.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/sobird/Meituan/Oasis_FE/node_modules/fsevents
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

个人经验,发现是每次升级xcode后,都会报这个错误,为避免再次出现该错误,本文记录下执行操作

终端执行下面命令

xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

如果出现以上结果,说明xcode-select --install命令不好使,放大招,执行下面的命令:

sudo rm -rf $(xcode-select -print-path)
xcode-select --install
等待完成

可能执行的时间比较长,耐心等待即可。