简体   繁体   English

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

i am new in react native i want to run react native app in IOS after react-native init, app not run in IOS show some error Showing All Messages bash: Native/social_login/socialLogin/node_modules/react-native/scripts/../Libraries: No such file or directory Command PhaseScriptExecution failed with a nonzero exit code and build failed please help me versions我是本机反应的新手我想在 react-native 初始化后在 IOS 运行本机应用程序,应用程序未在 IOS 中运行显示一些错误显示所有消息 bash: Native/social_login/socialLogin/node_modules/react-native/scripts/../Libraries : 没有这样的文件或目录Command PhaseScriptExecution 因非零退出代码而失败并且构建失败请帮助我版本
"react": "17.0.1", "react-native": "0.64.0" command line tools: Xcode 12.4 (12D4e) “react”:“17.0.1”,“react-native”:“0.64.0” 命令行工具:Xcode 12.4 (12D4e)

This happened also to me upgrading from 0.63 to 0.64.这也发生在我从 0.63 升级到 0.64 的身上。 After trying all solutions I followed a solution moving the folder to a directory where the path contain no spaces and it works and build the app successfully.在尝试了所有解决方案后,我遵循了一个解决方案,将文件夹移动到路径不包含空格的目录,并且它可以正常工作并成功构建应用程序。

Solution to React Native 0.64 build fail React Native 0.64 build 失败的解决方法

In order for this to work properly follow these steps:为了使其正常工作,请执行以下步骤:

  • If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues (ie npm uninstall -g react-native-cli)如果您之前安装了全局 react-native-cli package,请删除它,因为它可能会导致意外问题(即 npm uninstall -g react-native-cli)
  • Move the project folder in a path with no spaces (ie ~/sub folder name/ReactNativeApp won't work till you have spaces in the path, so move in a path like ~/folder/ReactNativeApp)将项目文件夹移动到没有空格的路径中(即~/子文件夹名称/ReactNativeApp 在路径中有空格之前将不起作用,因此请移入~/folder/ReactNativeApp 之类的路径中)
  • Then cd into the project folder and upgrade react native to the latest version with npx react-native upgrade and resolve conflicts if any然后 cd 进入项目文件夹并使用 npx react-native 升级本机到最新版本并解决冲突(如果有)
  • After upgrading remove the node_modules folder and the yarn.lock from the root and the podfile.lock and Pods folder from ios subfolder升级后从根目录中删除 node_modules 文件夹和 yarn.lock,从 ios 子文件夹中删除 podfile.lock 和 Pods 文件夹
  • Then cd back to the root and run yarn install && npx pod-install然后 cd 回到根目录并运行 yarn install && npx pod-install
  • Now run again your app in Xcode or your IDE and it works现在再次在 Xcode 或 IDE 中运行您的应用程序,它就可以工作了

Crazy and absurd that a space in the path-name could cause this issue路径名中的空格可能会导致此问题,这很疯狂和荒谬

Try to run pod install in ios folder尝试在 ios 文件夹中运行pod install

cd ios && pod install

Then when it's done go back to your main folder and run然后当它完成 go 回到你的主文件夹并运行

yarn run ios

If that doesn't work, check out the solutions here如果这不起作用,请在此处查看解决方案

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

There seems to be an issue with coreutils on macOS. macOS 上的coreutils似乎存在问题。

What fixed it for me is:为我解决的问题是:

  1. brew install coreutils
  2. brew install findutils
  3. brew install gnu-sed

Finally change the node_modules/react-native/scripts/generate-specs.sh to:最后将node_modules/react-native/scripts/generate-specs.sh更改为:


#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# This script collects the JavaScript spec definitions for core
# native modules and components, then uses react-native-codegen
# to generate native code.
#
# Optionally, set these envvars to override defaults:
# - SRCS_DIR: Path to JavaScript sources
# - CODEGEN_MODULES_LIBRARY_NAME: Defaults to FBReactNativeSpec
# - CODEGEN_MODULES_OUTPUT_DIR: Defaults to React/$CODEGEN_MODULES_LIBRARY_NAME/$CODEGEN_MODULES_LIBRARY_NAME
# - CODEGEN_COMPONENTS_LIBRARY_NAME: Defaults to rncore
# - CODEGEN_COMPONENTS_OUTPUT_DIR: Defaults to ReactCommon/react/renderer/components/$CODEGEN_COMPONENTS_LIBRARY_NAME
#
# Usage:
#   ./scripts/generate-specs.sh
#   SRCS_DIR=myapp/js CODEGEN_MODULES_LIBRARY_NAME=MySpecs CODEGEN_MODULES_OUTPUT_DIR=myapp/MySpecs ./scripts/generate-specs.sh
#

# shellcheck disable=SC2038

set -e

THIS_DIR=$(cd -P "$(gdirname "$(greadlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
TEMP_DIR=$(gmktemp -d /tmp/react-native-codegen-XXXXXXXX)
RN_DIR=$(cd "$THIS_DIR/.." && pwd)

# find node path
source "$RN_DIR/scripts/find-node.sh"

NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}"
USE_FABRIC="${USE_FABRIC:-0}"

cleanup () {
  set +e
  grm -rf "$TEMP_DIR"
  set -e
}

describe () {
  printf "\\n\\n>>>>> %s\\n\\n\\n" "$1"
}

main() {
  SRCS_DIR=${SRCS_DIR:-$(cd "$RN_DIR/Libraries" && pwd)}
  CODEGEN_MODULES_LIBRARY_NAME=${CODEGEN_MODULES_LIBRARY_NAME:-FBReactNativeSpec}

  CODEGEN_COMPONENTS_LIBRARY_NAME=${CODEGEN_COMPONENTS_LIBRARY_NAME:-rncore}
  CODEGEN_MODULES_OUTPUT_DIR=${CODEGEN_MODULES_OUTPUT_DIR:-"$RN_DIR/React/$CODEGEN_MODULES_LIBRARY_NAME/$CODEGEN_MODULES_LIBRARY_NAME"}
  # TODO: $CODEGEN_COMPONENTS_PATH should be programmatically specified, and may change with use_frameworks! support.
  CODEGEN_COMPONENTS_PATH="ReactCommon/react/renderer/components"
  CODEGEN_COMPONENTS_OUTPUT_DIR=${CODEGEN_COMPONENTS_OUTPUT_DIR:-"$RN_DIR/$CODEGEN_COMPONENTS_PATH/$CODEGEN_COMPONENTS_LIBRARY_NAME"}

  TEMP_OUTPUT_DIR="$TEMP_DIR/out"
  SCHEMA_FILE="$TEMP_DIR/schema.json"

  if [ -z "$NODE_BINARY" ]; then
    echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2
    exit 1
  fi

  CODEGEN_PATH=$("$NODE_BINARY" -e "console.log(require('path').dirname(require.resolve('react-native-codegen/package.json')))")

  # Special case for running CodeGen from source: build it
  if [ ! -d "$CODEGEN_PATH/lib" ]; then
    describe "Building react-native-codegen package"
    bash "$CODEGEN_PATH/scripts/oss/build.sh"
  fi

  describe "Generating schema from flow types"
  "$NODE_BINARY" "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR"

  describe "Generating native code from schema (iOS)"
  pushd "$RN_DIR" >/dev/null || exit 1
    "$NODE_BINARY" scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$CODEGEN_MODULES_LIBRARY_NAME"
  popd >/dev/null || exit 1

  describe "Copying output to final directory"
  gmkdir -p "$CODEGEN_COMPONENTS_OUTPUT_DIR" "$CODEGEN_MODULES_OUTPUT_DIR"
  gcp -R "$TEMP_OUTPUT_DIR/$CODEGEN_MODULES_LIBRARY_NAME.h" "$TEMP_OUTPUT_DIR/$CODEGEN_MODULES_LIBRARY_NAME-generated.mm" "$CODEGEN_MODULES_OUTPUT_DIR" || exit 1
  gfind "$TEMP_OUTPUT_DIR" -type f | gxargs gsed -i.bak "s/$CODEGEN_MODULES_LIBRARY_NAME/$CODEGEN_COMPONENTS_LIBRARY_NAME/g" || exit 1
  gfind "$TEMP_OUTPUT_DIR" -type f -not -iname "$CODEGEN_MODULES_LIBRARY_NAME*" -exec cp '{}' "$CODEGEN_COMPONENTS_OUTPUT_DIR/" ';' || exit 1

  echo >&2 'Done.'
}

trap cleanup EXIT
main "$@"


notice that some commands are starting with g like greadlink etc.请注意,某些命令以g开头,例如greadlink等。

if your get invalid identifier error in react-native-xcode.sh then under Build Phases -> Bundle React Native code and images it should be: (notice the double quotes):如果您在react-native-xcode.sh中出现invalid identifier错误,则在Build Phases -> Bundle React Native code and images下应该是:(注意双引号):

set -e
export NODE_BINARY="node ../node_modules/react-native/scripts/react-native-xcode.sh"

use patch-package react-native to patch it (if project is being developed on different machines then they must install the brew packages above)使用patch-package react-native来打补丁(如果项目正在不同的机器上开发,那么他们必须安装上面的 brew 包)

This is nothing just an issue with the scheme name for me, in my case my scheme name contains whitespace eg "ABC staging", which is not allowed, it got fixed after deleting and creating a new scheme with the name "ABC-staging".这对我来说只是方案名称的问题,在我的情况下,我的方案名称包含空格,例如“ABC staging”,这是不允许的,它在删除并创建一个名为“ABC-staging”的新方案后得到修复.

in the case of react-native 0.67^, you may need to apply these changes as well对于 react-native 0.67^,您可能还需要应用这些更改

change line no 7 
set -e. ==> set +e 

in

node_modules/react-native/scripts/find-node.sh

then use patch-package using the following command:然后使用以下命令使用补丁包:

npx patch-package react-native

this will create a patch file inside the patch folder in root, then you can add in the post-install script in package.json:这将在根目录下的补丁文件夹中创建一个补丁文件,然后您可以在 package.json 中添加安装后脚本:

 "postinstall": "npx patch-package"

This command will run each time a new package is getting added to the project and auto-fix react-native find-node.每次将新的 package 添加到项目中并自动修复 react-native 查找节点时,都会运行此命令。 sh.嘘。

Adding $(ARCHS_STANDARD) to Valid Architectures in Build Settings solved it for me$(ARCHS_STANDARD)添加到构建设置中的有效架构为我解决了这个问题

For me it was just having a space in folder name which was in the path of project folder from root.对我来说,它只是在文件夹名称中有一个空格,它位于根目录的项目文件夹路径中。

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

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

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 组件。

I had to delete the contents of my ~/.bash_profile file.我不得不删除~/.bash_profile文件的内容。

I don't even use bash, but some other script populated the file and that broke my build.我什至不使用 bash,但是其他一些脚本填充了该文件,这破坏了我的构建。 Deleting the contents fixed the build, immediately.删除内容立即修复了构建。 Might not work for you, but thought I'd share.可能不适合你,但我想我会分享。

I'm running Xcode 13.4.1我正在运行 Xcode 13.4.1
Installed cocoapods using brew install cocoapods ( https://brew.sh/index_es )使用brew install cocoapods 安装 cocoapodshttps://brew.sh/index_es
M2 apple chip M2苹果芯片
React Native 0.70反应原生 0.70

Actually after spending a whole lot of time trying different solutions none of them worked except for Giuseppe's answer.实际上,在花了很多时间尝试不同的解决方案之后,除了 Giuseppe 的回答之外,它们都没有奏效。 I had white spaces in my path "/React Native/exampleProject"我的路径“/React Native/exampleProject”中有空格

1. Renamed folders/files to remove any white space in the path (creating a fresh project within the fixed path worked with no problems at all) 1.重命名文件夹/文件以删除路径中的任何空白(在固定路径中创建一个新项目完全没有问题)

I didn't even had to execute pod install anymore in the ios folder我什至不必再在 ios 文件夹中执行pod install

In my case, i had to export the right path to node就我而言,我必须将正确的path导出到node

in your terminal type which node , copy the path and export it in ios/xcode.env在您的终端类型which node ,复制路径并将其导出到ios/xcode.env

export NODE_BINARY="copied node path"

暂无
暂无

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

相关问题 MacCatalina 上的 Xcode 版本 12.4“Command PhaseScriptExecution failed with a nonzero exit code” - Xcode Version 12.4 "Command PhaseScriptExecution failed with a nonzero exit code" on macCatalina 命令 PhaseScriptExecution 因 Xcode 中的非零退出代码而失败 - Command PhaseScriptExecution failed with a nonzero exit code in Xcode xcode 命令 PhaseScriptExecution 失败,退出代码为非零 - xcode Command PhaseScriptExecution failed with a nonzero exit code 显示最近的消息命令 PhaseScriptExecution 失败,退出代码为非零 xcode12 - Showing Recent Messages Command PhaseScriptExecution failed with a nonzero exit code xcode12 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 React Native - FBReactNativeSpec 命令 PhaseScriptExecution 失败,退出代码非零 - React Native - FBReactNativeSpec Command PhaseScriptExecution failed with a nonzero exit code 命令 PhaseScriptExecution 失败,退出代码为非零 iOS - Command PhaseScriptExecution failed with a nonzero exit code iOS React Native - 命令 PhaseScriptExecution 因非零退出代码 xcode 设置错误而失败 - React Native - Command PhaseScriptExecution failed with a nonzero exit code xcode setup error 构建时在 xcode 中出错 - PhaseScriptExecution 失败,退出代码非零 - Getting error in xcode while build - PhaseScriptExecution failed with a nonzero exit code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM