Failed to load bundle - Could not connect to development server - react-native

I've been looking for a solution to this issue for a day now but couldn't fix it.
I have not used react native for a month when everything was working fine.
Now, if I try to run an existing project that used to work (react native 0.59.5) or a brand new project (react native 0.59.9) with the iOS simulator on my mac, I get the error:
Failed to load bundle - Could not connect to development server
Any idea how I can fix this?

Ok found the issue. Was thinking it might be watchman related issue and wanted to use the command brew reinstall watchmanto reinstall it. By running this command, I found an error
Error: Xcode alone is not sufficient on Mojave. Install the Command Line Tools: xcode-select --install
Looks like the command line tools for xCode was not available anymore.
I launched the command xcode-select --install and then reinstalled watchman just in case. It is now working!

Couldn't connect to development server error
This error is received when the metro bundler isn't running in port 8081. To start the bundler, from project folder run:
npm start
Now, try reloading your app (ctrl + R for iOS / r+r for Android).
Also, check your terminal in case the project failed initial build due to some error.

Related

Expo won't start the simulator / emulator

I always used to start my Expo project by typing in the terminal expo start and then i (for iOS simulator). The day after iOS 16 got released, Expo started to behave differently. After running expo start it gave me a warning: This command is being executed with the global Expo CLI. Learn more: https://blog.expo.dev/the-new-expo-cli-f4250d8e3421
To use the local CLI instead (recommended in SDK 46 and higher), run:
› npx expo start and after pressing i it threw the following error:
Error running xcrun simctl help: You may need to run sudo xcode-select -s /Applications/Xcode.app and try again.
XDLError: You may need to run sudo xcode-select -s /Applications/Xcode.app and try again.
Unable to verify Xcode and Simulator installation. After this I killed the terminal and in a new one I decided to follow the command it gave me in the warning (after running expo start). I ran npx expo start and then i and it threw me a new error which was:
Unable to run simctl:
Error: xcrun exited with non-zero code: 72
CommandError: xcrun is not configured correctly. Ensure sudo xcode-select --reset works before running this command again., but this time it didn't gave me a warning before pressing i. I also tried to run the commands shown in the errors and re-run the app, but still the same errors were thrown. I updated my OS, XCode and also deleted and cloned the project again so i could re-install dependencies just in case something was wrong with them.
I have attached the GitHub repo link of one of my projects so you can test it as well. It's not just this project, it's all of the projects I use Expo, even the new ones won't start.
If anyone has any idea how to fix this and why this happens, I would really appreciate it :)
Uninstalled and re-installed Expo globally. Updated the simulator to iOS 16 and opened the simulator before running expo start. It works as it did before.

expo always returning me with "-bash: expo: command not found" everytime i go to set up a project, "expo init projectname". how do i resolve this?

have downloaded latest version of node.js on mac
terminal says ive downloaded latest version of expo cli
if i try to run my first project in terminal; expo init project name, am always met with the same error. -bash: expo: command not found.
when i check terminal to make sure that expo is installed, i am also met with: -bash: expo: command not found.
i have spent at least 3 days trying to resolve this problem.
any help towards this resolution would be greatly appreciated
How have you downloaded the Expo CLI? It may be important to note that if you don't install the package globally, like npm install -g expo-cli, it may not be properly executable.
[Additionally, One thing I've found when installing commands is that it can help to restart your terminal. Sometimes after you've installed something new, not everything will be in place, but it might be there when the terminal restarts.]

Getting Building iOS bundle error when trying to build an android app - expo -react-native

I was able to build app using expo build:android previously. However, after upgrading to latest expo version I get following error:
connect ECONNREFUSED 127.0.0.1:19001
Set EXPO_DEBUG=true in your env to view the stack trace.
I also see the following lines in the log:
Publishing to channel 'default'...
Building iOS bundle
I don't added ios to my app.json, I only need to build an android apk. To do that I use expo build:android -t app-bundle
I also removed package-lock.json and node_modules and run npm install, but I get the same error.
I run expo start on another cmd and then run expo build:android -t app-bundle still get same error
Also when I clear expo cache, see the following log:
Restarting Metro Bundler...
Starting Metro Bundler on port 19001.
Couldn't adb reverse: adb.exe: error: Invalid source port: 'undefined'
I had faced same issue myself and found the solution. Expo is looking for localhost:19001 which is not running. Just follow following steps and it should work as expected:
Run expo start no terminal and once it opens up the
browser where you will find this line written Starting Metro
Bundler on port 19001.
Now open another terminal instance and run expo build:android.

Expo React-Native iOS Simulator not working

Hello I'm facing a problem with Expo React-Native. Whenever I try to launch the iOS Simulator. I get this error:
Simulator is installed but is identified as 'com.apple.CoreSimulator.SimulatorTrampoline'; don't know what that is.
Simulator not installed. Please visit https://developer.apple.com/xcode/download/ to download Xcode and the iOS simulator. If you already have the latest version of Xcode installed, you may have to run the command `sudo xcode-select -s /Applications/Xcode.app`.
Screenshot of Expo Results
My NPM Version is 6.7.0
react-native-cli: 2.0.1
react-native: 0.57.1
Expo Version 2.11.9
Also I made sure my Command Line tools on Xcode is setup perfectly
Xcode CommandLineTools
Finally, I also tried to run the command sudo xcode-select -s /Applications/Xcode.app
Nothing works..
I had the same problem, fixed it by manually starting the simulator app before starting expo.
The app is located in /Applications/Xcode.app/Contents/Developper/Applications/Simulator.app
expo client:install:ios
This worked for me.
Manually opening the simulator first can help:
open -a Simulator
Then if using expo:
expo start
Finally click:
"Run on iOS simulator"
If it helps anyone else, the fix of opening the Simulator first was not working for me at first because I did not have command line tools installed. You can open xCode, go to preferences > locations > command line tools and if that is empty you'll need to install them. Once they are installed, expo start will give the same error as OP, but you can then use the open -a Simulator && expo start suggestion.
According to this thread What does com.apple.CoreSimulator.CoreSimulatorService do?, you can just execute the launch correctly the simulator.
killall -9 com.apple.CoreSimulator.CoreSimulatorService
Actually, it works to launch the simulator, but if I restart once the simulator, the problem is still here.
Update:
Apple provided a patch 10.2.1. After an update of XCode through the App Store, it seems working better. My simulator boots with an error, but after press "i" again in the terminal, it works correctly even if I restart the process.
Don't forget to update the latest version of expo-cli with npm install -g expo-cli
Simplest solution I have found; change your npm start script within the package.json file of your Expo project:
"start": "expo start", > "start": "open -a Simulator && expo start",
Yes you can fixed it temporarily by starting the simulator app before starting expo :
open -a Simulator; expo start
But the next time you open it, you have to run both commands again as well.
For now, you can aliasing start to open -a Simulator; expo start
Yup, additionally you have to give permissions every time you relaunch.. and because these are alerts.. the simulator takes forever to render. This is not an acceptable workflow. For now im just rendering on a device. Really hoping this gets fixed proper and soon.
🎉 I've been facing the same problem for a month, however I finally found a solution that worked for me:
Updated my Xcode to Version 11.1 ✨
Opened Xcode 11.1: (1) Double checked if "Xcode 11.1" was selected as my "Command Line Tool"; (2) Under the "Components" tab, I manually downloaded a simulator (iOS 12.2)
Updated Expo Client to #3.1.2 ✨
sudo npm install --unsafe-perm -g expo-cli
Updated Node.js from version 11.6.0 to 12.0.0
sudo npm install -g n
npm cache clean -f
Restarted my project & my simulator
npm start
✨ Which successfully launched my iOS simulator and built my project! ✨
Try to open the Simulator first from Xcode and then start Expo Metro.
For me I happen to learn that it requires all the three to make react native app run on the iOS simulator.
Xcode should be running
Simulator should be running
Expo Start and click on Run on iOS Simulator
It will then prompt on Simulator to install Expo Go for the first time and then would run app normally.
I was missing one or the other in my first two attempts to run the app on iOS Simulator.

npm server fails to start on brand new react native project

I just started on a fresh dev environment with Xcode 7.2.1, and installed react-native (0.20.0). I initialized a test project to see if it would run, and I got the following error:
~/dev/TestProj/node_modules/react-native/packager ~
packager.sh: line 11: node: command not found
The iOS Simulator screen says:
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
- Node server URL is correctly set in AppDelegate
URL: http://localhost:8081/index.ios.bundle?platform=ios&dev=true
Sure enough, if I go into the project folder in a terminal window and run 'npm start' from there, the packager starts and everything works. In my experience the packager should run by itself though when you run a project with React Native. Am I doing something wrong here or is there an issue? Never had this happen with previous versions of RN.
I moved on to trying to get my old project working, and while trying to use npm to add new packages, I added the following to my ~/.profile. I'm guessing this fixed it:
export NPM_DIR="$HOME/.npm" [ -s "$NPM_DIR/npm.sh" ] && . "$NPM_DIR/npm.sh"