每次我尝试npm安装。我得到以下错误。我该怎么解决呢?

gyp: No Xcode or CLT version detected!

我在节点-v→v8.8.0和npm -v→v6.11.3

我尝试在VSCode终端和iTerm上运行它,但最终都得到了相同的错误。(两者都更新到最新版本)。我做的唯一一件新事情是将我的macOS更新到最新版本(今天是Catalina 10.15.3)。

$ npm install          Fri Mar  6 17:22:40 2020

> fsevents@1.2.11 install /Users/synapse/Documents/synapsefi-dev-ui/node_modules/watchpack/node_modules/fsevents
> 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/synapse/.nvm/versions/node/v8.8.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:344:16)
gyp ERR! stack     at emitTwo (events.js:125:13)
gyp ERR! stack     at ChildProcess.emit (events.js:213:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 19.3.0
gyp ERR! command "/Users/synapse/.nvm/versions/node/v8.8.0/bin/node" "/Users/synapse/.nvm/versions/node/v8.8.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/synapse/Documents/synapsefi-dev-ui/node_modules/watchpack/node_modules/fsevents
gyp ERR! node -v v8.8.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok
npm WARN synapsefi-dev-ui@2.0.20 No repository field.
npm WARN The package country-data is included as both a dev and production dependency.
npm WARN The package react-dropzone is included as both a dev and production dependency.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/watchpack/node_modules/fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

当前回答

运行xcode-select——install尝试安装,但失败,报错如下:无法安装软件,因为当前软件更新服务器上不可用。以下是对我有效的方法。

OS: Catalina 10.15.6
Xcode-select version: 2373

注意:在运行所有这些操作之前,我已经安装了xcode-select version 2373。但是移除和重新安装解决了这个问题。

卸载xcode-select

Sudo rm -rf $(xcode-select -print-path)

去应用商店下载XCode。 打开XCode。在初始加载时,它将更新/安装东西。让这一切发生吧。 从Apple Developers手动下载Xcode 12的命令行工具 安装CLT for Xcode 12包。

现在应该可以开始了。

其他回答

这些答案都不适合我,因为我有一个损坏的XCode安装,一旦我卸载,npm又工作了

这适用于macOS Catalina 10.15.5版本:

$ xcode-select --print-path
/Applications/Xcode.app/Contents/Developer
$ sudo xcode-select --switch /Library/Developer/CommandLineTools
...
$ sudo xcode-select --reset
...

xcode命令行工具现在应该可以访问了。不需要重新安装任何东西。

即使你已经安装了它们(我的情况),但升级到Catalina(10.15.*)你可以得到这个错误(我的情况:))。

因此,简单的安装不会有帮助,因为你会得到一个错误,他们已经安装。

因此,你只需要(I)重置工具,或者在更糟糕的情况下(II)卸载并重新安装(需要大量重新下载)它(这是基于@Dane_duPlessis的答案)。

# just for а preview (not necessary)
xcode-select --print-path
# in my case it printed `/Library/Developer/CommandLineTools`

# could be useful if the path is making a problem
sudo xcode-select --switch /Library/Developer/CommandLineTools

# only for the (I) resetting case
sudo xcode-select --reset

# only for the (II) uninstalling case - the next line deletes folder returned by the `xcode-select --print-path` command
sudo rm -rf $(xcode-select --print-path)


# only for the (II) uninstalling case - install tools (again) if you don't get a default installation prompt
xcode-select --install

注意:

你不需要每个项目都这样做,但只需要做一次 也有讨论说,你必须在每次OSX更新时都这样做,在我的情况下,后来更新OSX系统没有再次触发这个问题

到:gyp:没有Xcode或CLT版本检测到macOS Catalina

我就是这么做的,我的问题现在没了。 第一: xcode-select——print-path 给出了path /Library/Developer/CommandLineTools

so:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

它会弹出安装窗口,只要安装,你就可以上路了。

谢谢Stackoverflow !

如果你根本不想安装Xcode命令行工具(就像我的情况)。

你可以尝试:

删除package-lock。Json文件和node_modules目录(如果存在的话) 又是NPM I

它执行时带有一些gyp警告,提示没有检测到Xcode或CLI版本,但工作正常