repack icon indicating copy to clipboard operation
repack copied to clipboard

How to start react native

Open KamalSilva007 opened this issue 3 years ago • 15 comments

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. image

The server is working fine. image

React Native version - "react": "18.2.0", "react-native": "0.72.0" "@callstack/repack": "^3.2.0"

Can you help with starting the project?

KamalSilva007 avatar Jun 22 '23 09:06 KamalSilva007

try npx react-native webpack-start and see if webpack server started or not

chakrihacker avatar Jun 22 '23 20:06 chakrihacker

Yes. It's working as I mentioned in the screenshot

KamalSilva007 avatar Jun 23 '23 07:06 KamalSilva007

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.

jbroma avatar Jun 26 '23 13:06 jbroma

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)

panoptical2 avatar Jun 28 '23 20:06 panoptical2

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)

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.

thonnicolas avatar Aug 05 '23 07:08 thonnicolas

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
	}
}

steventnorris avatar Oct 20 '23 21:10 steventnorris

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.

github-actions[bot] avatar Dec 06 '23 00:12 github-actions[bot]

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.

github-actions[bot] avatar Dec 21 '23 00:12 github-actions[bot]

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 avatar Apr 08 '24 11:04 omotayoR1

@omotayoR1 can you try upgrading to Re.Pack 4.0.0-rc.0 and check if the issue still exists? Thanks!

jbroma avatar Apr 08 '24 11:04 jbroma

@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 avatar Apr 08 '24 11:04 omotayoR1

@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

jbroma avatar Apr 08 '24 11:04 jbroma

@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. (C:\Users\directory\Documents\d\node_modules\fastify-favicon\src\plugin.js:60:14) at ReadFileContext.callback (C:\Users\directory\Documents\d\node_modules\graceful-fs\graceful-fs.js:123:16) at FSReqCallback.readFileAfterOpen [as oncomplete] (node:fs:306:13)

what do i do

Thanks for helping

omotayoR1 avatar Apr 08 '24 11:04 omotayoR1

looks like we introduced a regression on Windows, please create a new issue for this, thanks!

jbroma avatar Apr 08 '24 12:04 jbroma

looks like we introduced a regression on Windows, please create a new issue for this, thanks!

Okay thanks I will do that now

omotayoR1 avatar Apr 08 '24 12:04 omotayoR1