microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.33k stars 1.14k forks source link

React Native windows Release build stuck after "Done copying assets" #13636

Open IamJignesh opened 2 months ago

IamJignesh commented 2 months ago

Problem Description

React Native windows Release build stuck at "Done copying assets"

When a new React Native Windows project is created and the release build is run, it gets stuck at "Done copying assets" and does not proceed further.

This only happens on the first release build. Subsequent release builds work fine.

This is creating a problem for CI/CD pipelines where release build is stuck as it is the first build every time a new build is triggered.

When running locally, when the build gets stuck at Done copying assets, terminating the build (Ctrl+C) and running the release build again works fine.

Here are my full build logs: build.log

Steps To Reproduce

  1. npx --yes @react-native-community/cli@next init myapp --version "latest"
  2. cd myapp
  3. yarn add react-native-windows@latest
  4. npx react-native init-windows --overwrite --logging --template cpp-app
  5. npx react-native run-windows --arch x64 --release --logging

Build hangs when running the above steps: image

Expected Results

The app builds successfully the first time.

CLI version

14.0.0

Environment

System:
  OS: Windows 10 10.0.20348
  CPU: (8) x64 Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
  Memory: 11.18 GB / 16.00 GB
Binaries:
  Node:
    version: 19.9.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 3.6.4
    path: C:\Program Files\nodejs\yarn.CMD
  npm:
    version: 9.6.3
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    Versions:
      - 10.0.10240.0
      - 10.0.17763.0
      - 10.0.19041.0
      - 10.0.22000.0
      - 10.0.22621.0
IDEs:
  Android Studio: Not Found
  Visual Studio:
    - 17.11.35219.272 (Visual Studio Professional 2022)
    - 15.9.34407.156 (Visual Studio Professional 2017)
Languages:
  Java: Not Found
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.2
    wanted: 0.75.2
  react-native-windows:
    installed: 0.75.0
    wanted: latest
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Community Modules

{ "name": "myapp", "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", "test:windows": "jest --config jest.config.windows.js" }, "dependencies": { "react": "18.3.1", "react-native": "0.75.2", "react-native-windows": "latest" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@react-native/babel-preset": "0.75.2", "@react-native/eslint-config": "0.75.2", "@react-native/metro-config": "0.75.2", "@react-native/typescript-config": "0.75.2", "@rnx-kit/jest-preset": "^0.1.17", "@types/react": "^18.2.6", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.6.3", "eslint": "^8.19.0", "jest": "^29.6.3", "prettier": "2.8.8", "react-test-renderer": "18.3.1", "typescript": "5.0.4" }, "engines": { "node": ">=18" }, "packageManager": "yarn@3.6.4" }

Target Platform Version

10.0.22321

Target Device(s)

Desktop

Visual Studio Version

Visual Studio 2022

Build Configuration

Release

Snack, code example, screenshot, or link to a repository

No response

IamJignesh commented 2 months ago

On debugging it further I found that the issue is with react-native bundler, by running the following commands in isolation I can reproduce the issue:

  1. npx --yes @react-native-community/cli@next init myapp --version "latest"
  2. cd myapp
  3. yarn add react-native-windows@latest
  4. npx react-native init-windows --overwrite --logging --template cpp-app
  5. npx react-native bundle --platform windows --entry-file "index.js" --bundle-output "C:\Users\{userName}\Desktop\myapp\windows\myapp\Bundle\index.windows.bundle" --assets-dest "C:\Users\{userName}\Desktop\myapp\windows\myapp\Bundle" --dev false --reset-cache --sourcemap-output "C:\Users\{userName}\Desktop\myapp\windows\x64\Release\sourcemaps\react\index.windows.bundle.packager.map" --minify false

To workaround this issue, Firstly I am creating the following directory: C:\Users\{userName}\Desktop\myapp\windows\myapp\Bundle\assets\node_modules\react-native-windows\Libraries\NewAppScreen\components

and than running: npx react-native run-windows --arch x64 --release --logging

After adding the above workaround, the build no longer get's stuck at the "Done copying assets" step

jonthysell commented 1 month ago

I've seen this happen before but never consistently - something in Metro is obviously blocked when creating the bundle and copying the assets (maybe making the new folders is part of it) - unfortunately we don't know what folders to make independent of metro's bundling.