0

I have tried below steps to publish my React Native application for windows:

  • Open the solution in Visual Studio
  • Select the Release configuration from the Configuration Manager drop-down.
  • Build the solution. You can now launch without first launching Metro.
  • If you want to build an APPX package to share or publish, use the Project > Publish > Create App Packages... option.

Took reference from [https://microsoft.github.io/react-native-windows/docs/getting-started]

I have used below command to create my react-native application:

  • npx react-native init {projectName} --template react-native@^0.71.0
  • cd {projectName}
  • npx react-native-windows-init --overwrite
  • npx react-native run-windows

Here is my package.json looks like:

{
    "name": "SampleRNApp",
    "version": "0.0.1",
    "private": true,
    "scripts": {
      "android": "react-native run-android",
      "ios": "react-native run-ios",
      "lint": "eslint .",
      "start": "react-native start",
      "test": "jest",
      "windows": "react-native run-windows"
    },
    "dependencies": {
      "react": "18.2.0",
      "react-native": "0.71.0",
      "react-native-windows": "0.71.0"
    },
    "devDependencies": {
      "@babel/core": "^7.12.9",
      "@babel/preset-env": "^7.14.0",
      "@babel/runtime": "^7.12.5",
      "@react-native-community/eslint-config": "^3.0.0",
      "@tsconfig/react-native": "^2.0.2",
      "@types/jest": "^29.2.1",
      "@types/react": "^18.0.24",
      "@types/react-test-renderer": "^18.0.0",
      "babel-jest": "^29.2.1",
      "eslint": "^8.19.0",
      "jest": "^29.2.1",
      "metro-react-native-babel-preset": "0.73.5",
      "prettier": "^2.4.1",
      "react-test-renderer": "18.2.0",
      "typescript": "4.8.4",
      "metro-config": "^0.73.7"
    },
    "jest": {
      "preset": "react-native"
    }
  }

Observations:

For building the app it takes a hell lot of time (more than 30 mins) and after completing build successfully I'm not able to launch my RN application without Metro. It gives me error "A connection with the server could not be established" (see below error screen-shot).

System specs: I'm using Windows 11 OS and Visual Studio 2022 professional

After publishing I see there is an react-native application automatically installed into my system with the same name of my application and upon double clicking it I'm getting same error.

Error screen-shot: error screen-shot

Could you please advice me how we can create React Native application for Windows project, standalone package which will work without explicitly running Metro (without running npm start command).

Thanks in advance!

Ahmed Sbai
  • 10,695
  • 9
  • 19
  • 38

0 Answers0