`npm install` 在 node-gyp 重建时失败,带有 `gyp: No Xcode or CLT version detected!`

`npm install` fails on node-gyp rebuild with `gyp: No Xcode or CLT version detected!`

每次我尝试npm install。我收到以下错误。我该如何解决?

gyp: No Xcode or CLT version detected!

我在 node -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 或命令行工具

如果您的 Mac 已升级到 macOS Catalina (10.15),您需要通过 运行 xcode-select --install 安装 XCode 命令行工具。或者,如果您已经安装了完整的 Xcode,您可以在菜单 Xcode → Open Developer Tool → More Developer Tools.

下找到它们

即使您安装了它们(我的情况),但通过升级到 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: No Xcode or CLT version detected macOS Catalina

我遇到了同样的问题

我重新安装了命令行工具。

您需要找到安装目录。

xcode-select --print-path

删除现有安装:

sudo rm -r -f /Library/Developer/CommandLineTools

通过 运行 安装:

xcode-select --install

试试这些命令:

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

xcode-select --install

如果以上没有解决您的问题,您的安装路径可能有问题Xcode。如有必要,请使用以下帮助。

sudo xcode-select --switch /Library/Developer/CommandLineTools

sudo xcode-select --reset

当有新的 OS 更新时,大多数情况下都会发生这种情况。 但是我找到了解决这个问题的方法。您需要按照以下步骤来解决。

通过删除以前安装的版本重新安装命令行工具。

step1:首先获取命令行工具的安装位置

xcode-select --print-path

上述命令的结果/Library/Developer/CommandLineTools

step2: 删除文件夹

sudo rm -rf /Library/Developer/CommandLineTools

step3 - 再次安装

xcode-select --install

重新安装命令行开发人员工具后,当您从命令行 运行 任何 yarn 或 npm 命令时,gyp: No Xcode 或检测到 CLT 版本错误消息应该消失。

我就是这样做的,我的问题现在已经解决了。 第一的: xcode-select --print-path 它给出了路径 /Library/Developer/CommandLineTools

所以:

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

它会弹出安装 window,只需安装即可。

感谢 Whosebug!

这对我适用于 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 cli 工具现在应该可以访问了。无需重新安装任何东西。

在 catalina 上我做了以下操作:

xcode-select --print-path
sudo rm -rf /Library/Developer/CommandLineTools

由于安装命令不起作用,我不得不从以下位置下载它: https://developer.apple.com/download/more/

从那里安装:

XCode 12
Command Line Tools for XCode 12

Post 删除现有 node_modules 并通过 npm install 重新安装。成功了。

运行 xcode-select --install 尝试安装,但失败并出现以下错误:Can't install the software because it is not currently available from the Software Update server. 这是对我有用的方法。

OS: Catalina 10.15.6
Xcode-select version: 2373

注意:在 运行 所有这些之前,我已经安装了 xcode-select 版本 2373。但是删除并重新安装解决了这个问题。

  1. 卸载xcode-select

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

  1. 前往应用商店,下载XCode。

  2. 打开 XCode。在初始加载时,它会 update/install 东西。让这一切发生。

  3. 来自 Apple Developers,手动下载 Command Line Tools for Xcode 12

  4. 为 Xcode 12 包安装 CLT。

你现在应该可以开始了。

在 catalina 上必须从 https://developer.apple.com/download/more/

手动安装 xcode 的命令行工具

在 macOS Catalina 上:

  1. 使用命令 sudo rm -rf $(xcode-select --print-path);
  2. 卸载“Xcode 的命令行工具”
  3. More Downloads for Apple Developers 下载“Xcode 的命令行工具”,然后安装。

我想,到目前为止您可能已经尝试了多种解决方案,但如果这些解决方案中的 none 对您有效,请不要担心 - 我知道了。 :)

Non-working 解法:

  1. xcode-select --install 对我不起作用 (macOS Catalina 10.15.7),因为它显示了一个软件更新对话框,上面写着 Can't install the software because it is currently not available from the Software Update Server.
  2. 我还从 Apple 下载网站 (https://developer.apple.com/download/more/?=for%20Xcode) 下载并安装了 Xcode 命令行工具,但问题 re-appeared 不知何故或可能并没有首先解决它而且我不知何故没有注意到。
  3. sudo xcode-select --reset 对我来说也没用。
  4. 有人建议安装整个 XCode。不,谢谢。

工作解决方案:

这对我有用,即手动使用软件更新重新安装 Xcode 命令行工具。

  1. 使用以下命令检查要更新的软件列表中是否提到命令行工具更新:softwareupdate -l
  2. 如果该列表中未提及命令行工具更新,则使用以下命令将其手动添加到列表中,这将创建一个临时文件:sudo touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
  3. 再次验证列表现在是否包含 运行 softwareupdate -l 提到的命令行工具。
  4. 现在,按 Cmd+Space 启动 Mac 的 Spotlight 搜索。搜索 Software Update。启动 Software Update.
  5. 这将向您显示以下用于安装命令行工具的对话框。安装更新并快乐。 :)
  6. 删除第 2 步中创建的临时文件:sudo rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress

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

您可以尝试:

  1. 删除 package-lock.json 文件和 node_modules 目录(如果存在)
  2. 又是npm i

它执行时带有一些关于未检测到 Xcode 或 CLI 版本的 gyp 警告,但工作正常

这对我有用

sudo xcode-select --reset

我更新到 Big Sur 并在 Catalina 上一切正常时收到此错误。但是我升级了 xcode 并安装在另一个文件夹中。

安装在那个一切正常的文件夹中帮助了我

当我将 node-gyp 作为依赖项安装并 运行 在脚本中安装时,这发生在我身上。

我在全局安装后

npm i -g node-gyp

成功了! (大苏尔)

运行 以下命令与 sudo 一起重置您的命令行工具。

sudo xcode-select --reset

在我的例子中,我删除了 package.lock.json 并且它起作用了,我已经安装了 xCode

我尝试了所有方法,但没有任何效果。就个人而言,即使问题出在 gyp 上,也是 Next 出了问题。所以我降级了 node.js 版本。将 next.js 和 return 安装到最新版本。

None 这些答案对我有用,因为我安装了损坏的 XCode,卸载后,npm 再次工作

当项目需要节点版本 10 但我有 12+

时,我遇到了同样的错误