How to start react native
Ask your Question
I'm new to repack. I created the react native app with native CLI and followed your doc guide. (installed with npx @callstack/repack-init)
But when it comes to running the application, I can't start it.
The server is working fine.
React Native version - "react": "18.2.0", "react-native": "0.72.0" "@callstack/repack": "^3.2.0"
Can you help with starting the project?
try npx react-native webpack-start and see if webpack server started or not
Yes. It's working as I mentioned in the screenshot
Hi @KamalSilva007,
Have tried running adb reverse tcp:8081 tcp:8081 and then trying to connect to the server again? You can also try checking whether the app will connect to metro instead.
I've also found that using 10.0.2.2 instead of localhost in the Android emulator allows it to connect to Metro/Webpack. You can change this in the settings in the emulator by hitting Control + M, then clicking on settings, and click on "Debug server host & port for device", then typing the location of the debug server (usually 10.0.2.2:8081)
I've also found that using
10.0.2.2instead oflocalhostin the Android emulator allows it to connect to Metro/Webpack. You can change this in the settings in the emulator by hittingControl + M, then clicking on settings, and click on "Debug server host & port for device", then typing the location of the debug server (usually10.0.2.2:8081)
Thank you a lot i have the same issue and after I updated the Change Bundle Location to "localhost:8081" it is working fine for me.
If anyone else hits issues with this (I did), I use the following and it works fine for me:
package.json
"scripts": {
"start": "react-native webpack-start --host 127.0.0.1 --port 8082",
"android": "react-native run-android --no-packager --port 8082"
},
When running:
Terminal 1
yarn start
Terminal 2
adb reverse tcp:8082 tcp:8082
//ENTER TO EXECUTE
yarn android
I have the adb reverse for all my micros I'm running locally and the starts all in a vscode set of tasks I can run to make it easier, and it opens a little terminal for me to run the android command in. This is a PoC demo app so likely won't need to run several at once in a more production-level application, but if it's helpful the vs code workspace is below:
{
"folders": [
{
"name": "SuperappHost",
"path": "./SuperappHost"
},
{
"name": "MicrofrontendRemoteNative",
"path": "./MicrofrontendRemoteNative"
},
{
"name": "MicrofrontendRemoteWebview",
"path": "./MicrofrontendRemoteWebview"
}
{
"name": "NavigationProvider",
"path": "./NavigationProvider"
},
],
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "Superapp Start",
"dependsOn": ["SuperappHost Start", "MicrofrontendRemoteNative Start", "MicrofrontendRemoteWebview Start", "NavigationProvider Start", "Android TCP", "Host Shell"],
},
{
"label": "NavigationProvider Start",
"type": "shell",
"command": "zsh",
"args": ["-c", "yarn start"],
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder:NavigationProvider}"
}
},
{
"label": "SuperappHost Start",
"type": "shell",
"command": "zsh",
"args": ["-c", "yarn start"],
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder:SuperappHost}"
}
},
{
"label": "MicrofrontendRemoteNative Start",
"type": "shell",
"command": "zsh",
"args": ["-c", "yarn start"],
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder:MicrofrontendRemoteNative}"
}
},
{
"label": "MicrofrontendRemoteWebview Start",
"type": "shell",
"command": "zsh",
"args": ["-c", "yarn start"],
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder:MicrofrontendRemoteWebview}"
}
},
{
"label": "Android TCP",
"type": "shell",
"command": "zsh",
"args": ["-c", "adb reverse tcp:8081 tcp:8081 && adb reverse tcp:8082 tcp:8082 && adb reverse tcp:8083 tcp:8083 && adb reverse tcp:8084 tcp:8084"],
"presentation": {
"reveal": "silent",
"revealProblems": "onProblem",
"close": true
},
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder:SuperappHost}"
}
},
{
"label": "Host Shell",
"type": "shell",
"command": "zsh",
"args": [],
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder:SuperappHost}"
}
},
]
},
"settings": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.formatOnPaste": true,
"editor.formatOnSave": true
}
}
This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.
This issue has been automatically closed because it has been inactive for more than 14 days. Please reopen if you want to add more context.
adb reverse tcp:8081 tcp:8081
I have this same issue. whenever i run npx react-native webpack-start, it starts a server on port 8081 for me. After running npx react-native run-android, i get an error as quoted below:
"unable to load script. Make sure you are either running metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release
I have tried running it on metro and it starts the app perfectly.
NB: i use my android phone for preview
What do i do?
@omotayoR1 can you try upgrading to Re.Pack 4.0.0-rc.0 and check if the issue still exists? Thanks!
@omotayoR1 can you try upgrading to Re.Pack 4.0.0-rc.0 and check if the issue still exists? Thanks!
Thanks for your update
I just tried to upgrade and there was no matching version for @callstack/[email protected].
The latest i installed again is 3.0.1, what could be the cause?
Thank you
@omotayoR1 please bump the versions manually, the init won't install the newest version because it's an RC release
here's the link to npm: https://www.npmjs.com/package/@callstack/repack/v/4.0.0-rc.0
@omotayoR1 please bump the versions manually, the init won't install the newest version because it's an RC release
here's the link to npm: https://www.npmjs.com/package/@callstack/repack/v/4.0.0-rc.0
I just did that now and i'm not able to start the server by running 'npx react-native webpack-start' again. The error i'm getting below;
error fastify-favicon: \C:\Users\directory\Documents\d\node_modules@callstack\repack-dev-server\dist\img\favicon.ico not found.
Error: fastify-favicon: \C:\Users\directory\Documents\d\node_modules@callstack\repack-dev-server\dist\img\favicon.ico not found
at ReadFileContext.
what do i do
Thanks for helping
looks like we introduced a regression on Windows, please create a new issue for this, thanks!
looks like we introduced a regression on Windows, please create a new issue for this, thanks!
Okay thanks I will do that now