简体   繁体   English

React Native - FBReactNativeSpec 命令 PhaseScriptExecution 失败,退出代码非零

[英]React Native - FBReactNativeSpec Command PhaseScriptExecution failed with a nonzero exit code

I am using a MacBook Pro with我正在使用 MacBook Pro

  • M1 chip M1芯片
  • MacOS Big Sur MacOS 大苏尔
  • Xcode Version 13.2.1 Xcode 版本 13.2.1
  • node v14.17.5节点 v14.17.5

I wanted to follow this tutorial to set up a new React Native project called AwesomeProject https://reactnative.dev/docs/environment-setup the section with React Native CLI Quickstart.我想按照本教程设置一个名为 AwesomeProject 的新 React Native 项目https://reactnative.dev/docs/environment-setup React Native CLI Quickstart 部分。

When I try to run the app in terminal by typing: npx react-native run-ios my build fails with the following error:当我尝试通过键入以下命令在终端中运行应用程序时: npx react-native run-ios 我的构建失败并出现以下错误:

PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/thomashuber/Library/Developer/Xcode/DerivedData/AwesomeProject-aprperxvqrezbfeyvousbagyesvr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-5F4C70EF7D90A5A5BDAEB404279F232A.sh (in target 'FBReactNativeSpec' from project 'Pods') (1 failure) PhaseScriptExecution [CP-用户]\ Generate\ Specs /Users/thomashuber/Library/Developer/Xcode/DerivedData/AwesomeProject-aprperxvqrezbfeyvousbagyesvr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-5F4C70EF7D90A5A5BDAEB4324279 (在项目“Pods”的目标“FBReactNativeSpec”中)(1 次失败)

When I try to run it in Xcode either on a simulator or on an iPhone device I get the following error in FBReactNativeSpec :当我尝试在模拟器或 iPhone 设备上的 Xcode 中运行它时,我在FBReactNativeSpec中收到以下错误:

/bin/sh -c /Users/thomashuber/Library/Developer/Xcode/DerivedData/AwesomeProject-aprperxvqrezbfeyvousbagyesvr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-5F4C70EF7D90A5A5BDAEB404279F232A.sh /bin/sh -c /Users/thomashuber/Library/Developer/Xcode/DerivedData/AwesomeProject-aprperxvqrezbfeyvousbagyesvr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-5F4C70EF7D90A5A5BDAEB404279F232A.sh

Command PhaseScriptExecution failed with a nonzero exit code命令 PhaseScriptExecution 失败,退出代码非零

I restarted my MacBook, I deleted the project and tried it again.我重新启动了我的 MacBook,我删除了项目并再次尝试。 I cleaned the project in Xcode but none of it helps.我在 Xcode 中清理了项目,但没有任何帮助。 I suspect that it is due the M1 chip of my MacBook.我怀疑这是因为我的 MacBook 的 M1 芯片。

I managed to get rid of the FBReactNativeSpec error by editing the Project settings.通过编辑项目设置,我设法摆脱了 FBReactNativeSpec 错误。

Try the following:尝试以下操作:

  1. In Xcode select your app's project and then select the target.在 Xcode select 你的应用程序的项目,然后 select 目标。

  2. In Terminal enter the following command to find out the path of your node installation:在终端中输入以下命令以找出节点安装的路径:

which node

This should give you a path.这应该给你一个路径。 Something like:就像是:

/Users/thomashuber/.nvm/versions/node/v16.14.0/bin/node /Users/thomashuber/.nvm/versions/node/v16.14.0/bin/node

  1. Copy this path.复制此路径。

  2. In Xcode with the target selected click on Build Phases and open Bundle React Native code and images在 Xcode 中,选择目标,单击Build Phases并打开Bundle React Native 代码和图像

  3. Replace NODE_BINARY=node .替换NODE_BINARY=node Instead of node enter the path that you have copied so that it is something like this NODE_BINARY=/Users/thomashuber/.nvm/versions/node/v16.14.0/bin/node代替 node 输入您复制的路径,使其类似于NODE_BINARY=/Users/thomashuber/.nvm/versions/node/v16.14.0/bin/node

用节点路径替换节点

For me anyone of this solutions work because, with Xcode 14.2 and RN0.70.5, there is the following 2 files in ios folder which fixe node version with the path (I don't know since which version and which one adds this files):对我来说,这个解决方案中的任何一个都有效,因为在 Xcode 14.2 和 RN0.70.5 中, ios文件夹中有以下 2 个文件,它们用路径固定了节点版本(我不知道从哪个版本开始,哪个版本添加了这个文件):

  1. .xcode.env
  2. .xcode.env.local

If you are this files inside ios folder just do this (with or without nvm):如果你是ios文件夹中的这个文件,只需执行此操作(有或没有 nvm):

which node

And put the patch inside the .xcode.env.local like this:并将补丁放入.xcode.env.local ,如下所示:

export NODE_BINARY="/Users/Blabla/.nvm/versions/node/v16.14.0/bin/node"

If this files doesn't exist, try to add it and maybe Xcode will take it into account:如果这个文件不存在,尝试添加它,也许 Xcode 会考虑到它:

Inside ios/.xcode.envios/.xcode.env里面

# This `.xcode.env` file is versioned and is used to source the environment
# used when running script phases inside Xcode.
# To customize your local environment, you can create an `.xcode.env.local`
# file that is not versioned.

# NODE_BINARY variable contains the PATH to the node executable.
#
# Customize the NODE_BINARY variable here.
# For example, to use nvm with brew, add the following line
# . "$(brew --prefix nvm)/nvm.sh" --no-use
export NODE_BINARY=$(command -v node)

Inside ios/.xcode.env.localios/.xcode.env.local里面

export NODE_BINARY="/Users/Blabla/.nvm/versions/node/v16.14.0/bin/node"

It seems like nvm is messing with the build process and if you shut down your computer or did a recent upgrade to node or nvm something in the cache folder gets reset and the build fails.似乎 nvm 扰乱了构建过程,如果您关闭计算机或最近升级到 node 或 nvm,缓存文件夹中的某些内容将被重置并且构建失败。 Nvm is the culprit and the code surrounding it in the react native node_modules/react-native/scripts/find-node.sh script related to nvm. Nvm 是罪魁祸首,并且在与 nvm 相关的 react native node_modules/react-native/scripts/find-node.sh脚本中围绕它的代码。 Following this advice: https://stackoverflow.com/a/70104375/5927929 worked for me with a small change.遵循此建议: https://stackoverflow.com/a/70104375/5927929对我有用,只需稍作改动。

My specs: Mac intel chip RN 0.68.2 nvm (0.33.11) && node (v18.3.0) install我的规格:安装 Mac 英特尔芯片 RN 0.68.2 nvm (0.33.11) && node (v18.3.0)

Steps:脚步:

  1. nvm unalias default
  2. nvm alias default node
  3. Build in xcode...done内置 xcode...完成

Simply delete the FBReactNativeSpec file from the Pods as shown in the image below.只需从 Pod 中删除 FBReactNativeSpec 文件,如下图所示。 enter image description here在此处输入图像描述

Ok, worth trying this.好的,值得一试。

2 different solutions: 2种不同的解决方案:

1: As soon as we get this error message: 1:一旦我们收到此错误消息:

Always scroll up & read the issue if written in that log file.如果写入该日志文件,请始终向上滚动并阅读问题。 Any issues like syntax error or issue related to your js code (like multiple imports in your js files or if you had forgot to import something).任何问题,如语法错误或与您的 js 代码相关的问题(如 js 文件中的多个导入,或者您忘记导入某些内容)。 If yes, you can fix that first & re build it.如果是,您可以先修复它并重新构建它。

In my case I had multiple imports of one of the RN components.就我而言,我多次导入其中一个 RN 组件。

if not如果不

2: got to 'Keychain access' in your mac, lock & unlock login and re build it, this may help you. 2:在你的mac中进入'钥匙串访问',锁定和解锁登录并重新构建它,这可能会对你有所帮助。

And make sure to 'cd ios' && 'pod install' if you have forgot to do it after installing any of the npm package.如果您在安装任何 npm package 后忘记执行此操作,请确保“cd ios”&&“pod install”。

  1. Determine what your node binary is:确定您的节点二进制文件是什么:

    $ which node /opt/homebrew/bin/node $ 哪个节点 /opt/homebrew/bin/node

  2. Add a fixer function in your Podfile:在 Podfile 中添加修复程序 function:

    def fix_fb_react_native_spec(installer) installer.pods_project.targets.each do |target| def fix_fb_react_native_spec(installer) installer.pods_project.targets.each 做 |target| if target.name == 'FBReactNativeSpec' target.build_configurations.each do |config| if target.name == 'FBReactNativeSpec' target.build_configurations.each 做 |config| if config.name == 'Debug' or config.name == 'Release' config.build_settings['NODE_BINARY'] = '/opt/homebrew/bin/node' end end end end end如果 config.name == 'Debug' 或 config.name == 'Release' config.build_settings['NODE_BINARY'] = '/opt/homebrew/bin/node' end end end end end

  3. In your postinstall, add fix_fb_react_native_spec(installer) like so:在您的安装后,像这样添加 fix_fb_react_native_spec(installer):

    post_install do |installer| post_install 做 |安装程序| react_native_post_install(installer) fix_fb_react_native_spec(installer) end react_native_post_install(installer) fix_fb_react_native_spec(installer) end

  4. Pod install吊舱安装

  5. Rebuild (ideally with a clean build)重建(最好是干净的构建)

In my case this error raising due to node path is not set in PATH Variables.在我的情况下,由于节点路径而引发的此错误未在 PATH 变量中设置。 Try to run below command it will set missing node path in PATH variable and it resolve the error.尝试运行以下命令,它将在 PATH 变量中设置缺少的节点路径并解决错误。

sudo ln -s $(which node) /usr/local/bin/node sudo ln -s $(哪个节点) /usr/local/bin/node

https://reactnative.dev/docs/new-architecture-troubleshooting#:~:text=Command%20PhaseScriptExecution%20failed%20with%20a,libraries%20(FBReactNativeSpec%2C%20rncore) . https://reactnative.dev/docs/new-architecture-troubleshooting#:~:text=Command%20PhaseScriptExecution%20failed%20with%20a,libraries%20(FBReactNativeSpec%2C%20rncore)

In my case:就我而言:

  • M1 chip M1芯片
  • MacOS Monterey macOS 蒙特雷
  • Xcode Version 13.2.1 Xcode 版本 13.2.1
  • node v16.6.0节点 v16.6.0
  • react-native 0.69 react-native 0.69

I was trying to build the iOS app via terminal under Rossetta.我试图通过 Rossetta 下的终端构建 iOS 应用程序。 Once I tried to use native M1 terminal - it worked well.一旦我尝试使用本机 M1 终端 - 它运行良好。

Go to your applications, right click on the app, get info, check OFF Open using Rossetta Go 到您的应用程序,右键单击应用程序,获取信息,检查关闭Open using Rossetta

在此处输入图像描述

In case someone else tried everything mentioned here and in other threads, and it didn't work, here is what worked for me!万一其他人尝试了此处和其他线程中提到的所有内容,但没有用,这对我有用!

[:] CocoaPods could not find compatible versions for pod "hermes-engine". [:] CocoaPods 找不到 pod“hermes-engine”的兼容版本。 In snapshot (Podfile:lock): hermes-engine (from ../node_modules/react-native/sdks/hermes/hermes-engine.podspec ) In Podfile: hermes-engine (from ../node_modules/react-native/sdks/hermes/hermes-engine.podspec ) It seems like you've changed the version of the dependency hermes-engine and it differs from the version stored in Pods/Local Podspecs .在快照中 (Podfile:lock): hermes-engine (from ../node_modules/react-native/sdks/hermes/hermes-engine.podspec ) 在 Podfile: hermes-engine (from ../node_modules/react-native/sdks/hermes/hermes-engine.podspec ) 看来您已经更改了依赖hermes-engine的版本,它与存储在Pods/Local Podspecs中的版本不同。 You should run pod update hermes-engine --no-repo-update to apply changes made locally.您应该运行pod update hermes-engine --no-repo-update以应用本地所做的更改。

But instead of running the command they gave me, I deleted Podfile.lock and the Pods directory , then reran pod install , and the build finally worked!但是我没有运行他们给我的命令,而是删除了Podfile.lock和 Pods 目录,然后重新运行pod install ,构建终于成功了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FBReactNativeSpec,PhaseScriptExecution 失败,退出代码非零 - FBReactNativeSpec, PhaseScriptExecution failed with a nonzero exit code React-Native 错误:命令 PhaseScriptExecution 失败,退出代码非零 - React-Native error: Command PhaseScriptExecution failed with a nonzero exit code 命令 PhaseScriptExecution 失败,退出代码非零:React Native - Command PhaseScriptExecution failed with a nonzero exit code : React Native 命令PhaseScriptExecution失败,出现非零退出代码 - errSecInternalComponent - Command PhaseScriptExecution failed with a nonzero exit code - errSecInternalComponent 命令 PhaseScriptExecution 因 Xcode 中的非零退出代码而失败 - Command PhaseScriptExecution failed with a nonzero exit code in Xcode 命令 PhaseScriptExecution 失败,退出代码为非零 flutter - Command PhaseScriptExecution failed with a nonzero exit code flutter Xcode 12.4 React 本机构建在 IOS 中失败显示所有消息命令 PhaseScriptExecution 因非零退出代码而失败 - Xcode 12.4 React native build failed in IOS Showing All Messages Command PhaseScriptExecution failed with a nonzero exit code 命令 PhaseScriptExecution 失败,退出代码为非零 iOS - Command PhaseScriptExecution failed with a nonzero exit code iOS xcode 命令 PhaseScriptExecution 失败,退出代码为非零 - xcode Command PhaseScriptExecution failed with a nonzero exit code React Native - 命令 PhaseScriptExecution 因非零退出代码 xcode 设置错误而失败 - React Native - Command PhaseScriptExecution failed with a nonzero exit code xcode setup error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM