ios React 在任何根目录中都找不到入口文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29388704/
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
React cannot find entry file in any of the roots
提问by Bocaxica
I am using React Native as a Pod in my iOS project. When I try to load a view that I created with React Native I get the Error screen referring me to the Terminal window where npm is running.
我在我的 iOS 项目中使用 React Native 作为 Pod。当我尝试加载使用 React Native 创建的视图时,出现错误屏幕,将我指向运行 npm 的终端窗口。
In the Terminal the error I am seeing is: Error: Cannot find entry file in any of the roots:
在终端中,我看到的错误是:错误:无法在任何根目录中找到条目文件:
I tried a few things, moving the file to a different location, but no luck. I did run "npm start" and I am looking for the file in "http://localhost:8081/". The current location of the file is in the same location as where I ran "npm start" from.
我尝试了几件事,将文件移动到其他位置,但没有运气。我确实运行了“npm start”,我正在“ http://localhost:8081/”中查找文件。文件的当前位置与我运行“npm start”的位置相同。
I am completely stuck here. Did I configure something wrong. How can I troubleshoot from here?
我完全被困在这里。是不是我配置错了。我如何从这里排除故障?
采纳答案by Bocaxica
Sorry for answering my own question (a bit lame), but I hope it helps somebody else.
很抱歉回答我自己的问题(有点蹩脚),但我希望它可以帮助其他人。
Apperantly we need run the npm command by giving an alternative path.
显然,我们需要通过提供替代路径来运行 npm 命令。
npm run start -- --root <directory_with_your_react_component_js_sources>
On http://facebook.github.io/react-native/docs/embedded-app.html#contentis a guide on how to integrate React Native in an existing app.
在http://facebook.github.io/react-native/docs/embedded-app.html#content是如何整合现有的应用程序阵营本土的指南。
回答by Preet V
Check for the node server running in one of the bash terminal, this was probably kicked by previous ReactNative XCode project you launched earlier. Stop that process and run XCode project again, this should fix the problem.
检查在其中一个 bash 终端中运行的节点服务器,这可能是由您之前启动的以前的 ReactNative XCode 项目启动的。停止该过程并再次运行 XCode 项目,这应该可以解决问题。
回答by Steve Lee Marreros Chuco
That happens when React wants to use a port that is already being used by other application. Since React listens to port 8081, you can get the process running at that port typing the following in Shell:
当 React 想要使用已被其他应用程序使用的端口时,就会发生这种情况。由于 React 侦听端口 8081,因此您可以在该端口上运行进程,在 Shell 中键入以下内容:
lsof -n -i4TCP:8081
You'll get an answer like this:
你会得到这样的答案:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 28571 username 32u IPv6 0x742e2ab233abdb9f 0t0 TCP *:sunproxyadmin (LISTEN)
node 28571 username 32u IPv6 0x742e2ab233abdb9f 0t0 TCP *:sunproxyadmin (LISTEN)
Just killed that by typing in shell
kill -9 <PID>
. Use the same PID that has been provided in the last answer.
刚刚通过输入 shell 杀死了它
kill -9 <PID>
。使用上一个答案中提供的相同 PID。
Then run npm start
.
然后运行npm start
。
回答by Colin Ramsay
There's this issue:
有这个问题:
https://github.com/facebook/react-native/issues/541
https://github.com/facebook/react-native/issues/541
Which seems the same thing. The user there seemed to indicate that they had run the project from that directory before, which leads me to wonder if this is due to a hanging or left-over packager from a previous run? Try closing the terminal window and re-running the Xcode project.
这似乎是同一件事。那里的用户似乎表示他们之前曾从该目录运行过该项目,这让我想知道这是否是由于上次运行时挂起或遗留的打包程序造成的?尝试关闭终端窗口并重新运行 Xcode 项目。
In general this sounds like an issue with the packager not generating the files as expected. Are there any other messages in the terminal window?
一般来说,这听起来像是打包程序没有按预期生成文件的问题。终端窗口中是否还有其他消息?
回答by Scott Skiles
I wanted to update this after getting a bit frustrated my setup still wasn't working after killing all node processes and running the command above.
我有点沮丧后想更新它,我的设置在杀死所有节点进程并运行上面的命令后仍然无法正常工作。
There seems to be a ReactNative open issue at present: https://github.com/facebook/react-native/issues/14246
目前似乎有一个 ReactNative open issue:https: //github.com/facebook/react-native/issues/14246
The solution for this is to kill the externally launched package manager and just run "npm start"in the project folder.
解决方案是杀死外部启动的包管理器,然后在项目文件夹中运行“npm start”。
回答by Kimmo Laine
Check if you have index.ios
or index
in your AppDelegate.m:
检查您是否有index.ios
或index
在您的AppDelegate.m 中:
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
I had index
and I was previously using index.ios
and index.android
so that's why it was failing.
我曾经index
并且我以前使用过index.ios
,index.android
所以这就是它失败的原因。
回答by Ilya Lee
In my experience, it is because of Watchman and Jest.
根据我的经验,这是因为 Watchman 和 Jest。
The solution I've found is add
我找到的解决方案是添加
name = name.replace('/', '\');
to 'node_modules\jest-haste-map\build\crawlers\watchman.js'
到 'node_modules\jest-haste-map\build\crawlers\watchman.js'
You can check further info here Watchman not working with React Native
您可以在此处查看更多信息 Watchman 不使用 React Native