简体   繁体   English

为什么在尝试运行新的 React Native 项目时出现错误

[英]Why am I getting an error when trying to run a new react native project

I have created a new react native project by running "react-native init MyFirstProject".我通过运行“react-native init MyFirstProject”创建了一个新的 react native 项目。 I have also installed node and have added no code of my own to any of the files.我还安装了节点并且没有向任何文件添加我自己的代码。

I have tried to run the project to make sure it works by running "react-native run-ios --simulator="iPhone 8"".我试图通过运行“react-native run-ios --simulator="iPhone 8"”来运行该项目以确保其正常工作。 The command runs successfully but I am given the following error.该命令成功运行,但出现以下错误。

Could not connect to development server.无法连接到开发服务器。

Ensure the following:确保以下几点:

  • Node server is running and available on the same.network - run 'npm start' from react-native root节点服务器正在运行并在同一网络上可用 - 从 react-native root 运行“npm start”
  • Node server URL is correctly set in AppDelegate AppDelegate 中正确设置了节点服务器 URL
  • WiFi is enabled and connected to the same.network as the Node Server WiFi 已启用并连接到与节点服务器相同的网络

URL: http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false URL: http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false

RCTFatal __28-[RCTCxxBridge handleError:]_block_invoke RCTFatal __28-[RCTCxxBridge handleError:]_block_invoke

_dispatch_call_block_and_release _dispatch_call_block_and_release

_dispatch_client_callout _dispatch_client_callout

_dispatch_main_queue_callback_4CF _dispatch_main_queue_callback_4CF

CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE

__CFRunLoopRun __CFRun循环运行

CFRunLoopRunSpecific Blockquote GSEventRunModal CFRunLoopRunSpecific Blockquote GSEventRunModal

UIApplicationMain UIApplicationMain

main主要的

start开始

How do I fix this error?我该如何解决这个错误?

Try opening your project ios/MyFirstProject/MyFirstProject.xcworkspace and see if there's any build error.尝试打开您的项目ios/MyFirstProject/MyFirstProject.xcworkspace并查看是否有任何构建错误。

I ran into this problem too, with the same error:我也遇到了这个问题,同样的错误:

RCTFatal __28-[RCTCxxBridge handleError:]_block_invoke

It turned out that I had another server running on my local machine on the same port that the expo development client server was running ( :8081 ), and that it was taking priority and then obviously giving the client a very different response to what it was expecting.事实证明,我在本地计算机上运行的另一台服务器与 expo 开发客户端服务器运行的端口相同( :8081 ),并且它具有优先权,然后显然给客户端一个非常不同的响应期待。 Quitting the other server fixed the problem.退出其他服务器解决了问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM