反应本机错误 - react-native-xcode.sh: line 45: react-native: command not found 命令 /bin/sh 失败,退出代码 127

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33650380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:11:31  来源:igfitidea点击:

React native error - react-native-xcode.sh: line 45: react-native: command not found Command /bin/sh failed with exit code 127

iosnode.jsxcodereact-native

提问by Jacob

I get this error when trying to build any (new or old) project. My node is on version 4.2.1 and react-native is on version 0.1.7. I've looked at other people with the same problem so I've updated react-native to the latest version however I still cannot build any project through xcode.

尝试构建任何(新的或旧的)项目时出现此错误。我的节点是 4.2.1 版,而 react-native 是 0.1.7 版。我看过其他有同样问题的人,所以我已经将 react-native 更新为最新版本,但是我仍然无法通过 xcode 构建任何项目。

采纳答案by Pikachu-go

To solve this problem use following steps :

要解决此问题,请使用以下步骤:

  • Use node version v4.2.1
  • cd into [your app]/node_modules/react-native/packager
  • $sh ./packager.sh (for some reason this runs fine)
  • Go into XCode and go to the Build Phases tab. Remove the last item on the list (the one that runs the script). So you're left with Target Dependencies, Compile Sources, Link Binary With Libraries, and Copy Bundle Resources.
  • 使用节点版本 v4.2.1
  • cd 进入 [你的应用程序]/node_modules/react-native/packager
  • $sh ./packager.sh (出于某种原因,这运行良好)
  • 进入 XCode 并转到 Build Phases 选项卡。删除列表中的最后一项(运行脚本的一项)。因此,您只剩下目标依赖项、编译源、将二进制文件链接到库和复制捆绑资源。

Now hit build in XCode. Since the shell script is no longer part of the XCode build routine, it shouldn't fail. And if you have the react native client server running in another terminal window, then everything should run fine.

现在点击在 XCode 中构建。由于 shell 脚本不再是 XCode 构建例程的一部分,因此它不会失败。如果您在另一个终端窗口中运行了 React Native 客户端服务器,那么一切都应该运行良好。

回答by Darius

If you are using RN 0.46 or above:

如果您使用的是 RN 0.46 或更高版本:

There is a breaking change made by Facebook: the location of the script has been changed, more detail here

Facebook 进行了重大更改:脚本的位置已更改,更多细节在这里

I was able to solve this error by:

我能够通过以下方式解决此错误:

  • Opening the project in XCode
  • Navigate to Build Phases > Bundle React Native code and images
  • Change export NODE_BINARY=node ../node_modules/react-native/packager/react-native-xcode.shto export NODE_BINARY=node ../node_modules/react-native/scripts/react-native-xcode.sh
  • 在 XCode 中打开项目
  • 导航 Build Phases > Bundle React Native code and images
  • 更改export NODE_BINARY=node ../node_modules/react-native/packager/react-native-xcode.shexport NODE_BINARY=node ../node_modules/react-native/scripts/react-native-xcode.sh

Notice how packageris now scripts, which is where that file actually lives in latest version of RN

请注意packager现在scripts是如何,这是该文件在最新版本的 RN 中实际存在的位置

enter image description here

在此处输入图片说明

回答by mutp

I added source ~/.bash_profileto the top of my [project_name]/node_modules/react-native/packager/react-native-xcode.sh file and it works.

我添加source ~/.bash_profile到我的 [project_name]/node_modules/react-native/packager/react-native-xcode.sh 文件的顶部,它可以工作。

See https://github.com/facebook/react-native/issues/3948

https://github.com/facebook/react-native/issues/3948

回答by Tibin Thomas

Simply change

简单地改变

../node_modules/react-native/packager/react-native-xcode.sh

to

../node_modules/react-native/scripts/react-native-xcode.sh

at

Xcode -> Select your Project -> "Build Phases" tab -> "Bundle React Native code and images"

Xcode -> 选择你的项目 -> “Build Phases” 选项卡 -> “Bundle React Native code and images”