react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

Hermes bytecode compilation fails in release mode when app is included in a separate wapproj project

Open WilliamWelsh opened this issue 4 months ago • 14 comments

Problem Description

Continued from https://github.com/microsoft/react-native-windows/issues/12258

I made this into a new issue since my old one started out with a different issue.

I have a packaged solution, where my React Native Windows app is the startup, with a .NET Framework background process that is run via full trust. I've boiled it down to just setting up a packaged project causes the error.

If I make a new project, Hermes in release runs fine. Once I add to a packaged project, it fails to run.

If UseHermes is disabled, it runs fine.

When searching for similar error messages (on other react native projects), they all fixed it by doing something regarding ram bundle

  • https://github.com/facebook/react-native/issues/27123#issuecomment-549954882
  • https://github.com/fastlane/fastlane/issues/17657#issuecomment-732764675
  • https://github.com/facebook/react-native/issues/37479#issuecomment-1651735599

Here is the output below from doing the steps under "Steps To Reproduce"

Build started at 10:22 AM...
1>------ Build started: Project: test, Configuration: Release x64 ------
1>  Running [npx react-native bundle --platform windows --entry-file index.js --bundle-output C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle --assets-dest C:\Users\william.welsh\Downloads\test\windows\test\Bundle --dev false --reset-cache --sourcemap-output C:\Users\william.welsh\Downloads\test\windows\test\bin\x64\Release\sourcemaps\react\index.windows.bundle.packager.map --minify false] to build bundle file.
1>EXEC : warning : the transform cache was reset.
1>                  Welcome to Metro v0.80.5
1>                Fast - Scalable - Integrated
1>  
1>  
1>  info Writing bundle output to:, C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle
1>  info Writing sourcemap output to:, C:\Users\william.welsh\Downloads\test\windows\test\bin\x64\Release\sourcemaps\react\index.windows.bundle.packager.map
1>  info Done writing bundle output
1>  info Done writing sourcemap output
1>  info Copying 1 asset files
1>  info Done copying assets
1>  Running [C:\Users\william.welsh\.nuget\packages\microsoft.javascript.hermes\0.1.18\tools\native\release\x86\hermes.exe -emit-binary -out C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle.hbc C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle -O -output-source-map] to precompile bundle file.
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(2634,18): warning G2BA5DD72: the variable "DebuggerInternal" was not declared in function "__shouldPauseOnThrow"
1>            typeof DebuggerInternal !== 'undefined' &&
1>                   ^~~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(6308,7): warning GB72B04CF: the variable "setTimeout" was not declared in function "logCapturedError"
1>        setTimeout(function () {
1>        ^~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(4277,108): warning G6B002900: the variable "nativeFabricUIManager" was not declared in function "onChange"
1>        (fromOrTo = fromOrTo && fromOrTo.stateNode) && fromOrTo.canonical._internalInstanceHandle ? (from && nativeFabricUIManager.setIsJSResponder(from.stateNode.node, false, blockNativeResponder || false), to && nativeFabricUIManager.setIsJSResponder(to.stateNode.node, true, blockNativeResponder || false)) : null !== to ? _$$_REQUIRE(_dependencyMap[2]).UIManager.setJSResponder(to.stateNode.canonical._nativeTag, blockNativeResponder) : _$$_REQUIRE(_dependencyMap[2]).UIManager.clearJSResponder();
1>                                                                                                             ^~~~~~~~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(4889,21): warning G71EC756D: the variable "clearTimeout" was not declared in anonymous function " 115#"
1>      cancelTimeout = clearTimeout;
1>                      ^~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(8639,30): warning GE03A48E9: the variable "__REACT_DEVTOOLS_GLOBAL_HOOK__" was not declared in anonymous function " 115#"
1>    if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1>                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(11008,5): warning G77E22827: the variable "setImmediate" was not declared in function "handleResolved"
1>      setImmediate(function () {
1>      ^~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15154,12): warning GB21C39AA: the variable "fetch" was not declared in anonymous function " 347#"
1>      fetch: fetch,
1>             ^~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15155,14): warning G977A4F98: the variable "Headers" was not declared in anonymous function " 347#"
1>      Headers: Headers,
1>               ^~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15156,14): warning GA9DF0D4B: the variable "Request" was not declared in anonymous function " 347#"
1>      Request: Request,
1>               ^~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15157,15): warning GBA394B55: the variable "Response" was not declared in anonymous function " 347#"
1>      Response: Response
1>                ^~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15314,24): warning G7B5B9C2F: the variable "FileReader" was not declared in function "readBlobAsArrayBuffer"
1>        var reader = new FileReader();
1>                         ^~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15365,36): warning G2EA34993: the variable "Blob" was not declared in anonymous function " 358#"
1>          } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
1>                                     ^~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15367,40): warning G1B27C27E: the variable "FormData" was not declared in anonymous function " 358#"
1>          } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
1>                                         ^~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15369,44): warning G057317F1: the variable "URLSearchParams" was not declared in anonymous function " 358#"
1>          } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
1>                                             ^~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15488,26): warning G76EBB7FD: the variable "AbortController" was not declared in anonymous function " 364#"
1>            var ctrl = new AbortController();
1>                           ^~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15622,23): warning G6D8B000F: the variable "XMLHttpRequest" was not declared in anonymous function " 368#"
1>          var xhr = new XMLHttpRequest();
1>                        ^~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(15167,71): warning GA1281092: the variable "self" was not declared in anonymous function " 350#"
1>      var g = typeof globalThis !== 'undefined' && globalThis || typeof self !== 'undefined' && self ||
1>                                                                        ^~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(25917,27): warning G37EDA9A9: the variable "performance" was not declared in anonymous function " 672#"
1>    if ("object" === typeof performance && "function" === typeof performance.now) {
1>                            ^~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(25940,26): warning G08945F78: the variable "navigator" was not declared in anonymous function " 672#"
1>    "undefined" !== typeof navigator && undefined !== navigator.scheduling && undefined !== navigator.scheduling.isInputPending ? navigator.scheduling.isInputPending.bind(navigator.scheduling) : null;
1>                           ^~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(26050,37): warning G121C250D: the variable "MessageChannel" was not declared in anonymous function " 672#"
1>    };else if ("undefined" !== typeof MessageChannel) {
1>                                      ^~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(26065,34): warning G7AAC3233: the variable "nativeRuntimeScheduler" was not declared in anonymous function " 672#"
1>    var Y = "undefined" !== typeof nativeRuntimeScheduler ? nativeRuntimeScheduler.unstable_UserBlockingPriority : 2,
1>                                   ^~~~~~~~~~~~~~~~~~~~~~
1>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(42362,34): warning GA4D07A9C: the variable "requestAnimationFrame" was not declared in function "start 9#"
1>            this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this));
1>                                   ^~~~~~~~~~~~~~~~~~~~~
1>  - Checking auto-linked files...
1>  √ Checking auto-linked files...
1>  Success: No auto-linking changes necessary. (13ms)
1>  - Running x64 node on a x64 machine
1>  i Running x64 node on a x64 machine
1>  - Running codegen-windows...
1>  
1>  i No codegenConfig specified in package.json - Skipping codegen-windows
1>  Success: No codegen-windows changes necessary. (1ms)
1>  Microsoft.ReactNative.Managed.CodeGen -> C:\Users\william.welsh\Downloads\test\node_modules\react-native-windows\target\x64\Release\Microsoft.ReactNative.Managed.CodeGen\Microsoft.ReactNative.Managed.CodeGen.dll
1>  Microsoft.ReactNative.Managed.CodeGen -> C:\Users\william.welsh\Downloads\test\node_modules\react-native-windows\target\x64\Release\Microsoft.ReactNative.Managed.CodeGen\publish\
1>  Parsing source files [90 milliseconds]
1>  Loading references [18 milliseconds]
1>  Compiling [816 milliseconds]
1>  Finding types [6 milliseconds]
1>  Generating code [22 milliseconds]
1>  test -> C:\Users\william.welsh\Downloads\test\windows\test\bin\x64\Release\test.exe
1>  Determining projects to restore...
1>  All projects are up-to-date for restore.
1>  Determining projects to restore...
1>  Applying temporary patches to folly.
1>  Determining projects to restore...
1>  Determining projects to restore...
1>  All projects are up-to-date for restore.
1>  Determining projects to restore...
1>  Determining projects to restore...
1>  Determining projects to restore...
1>  Applying temporary patches to fmt.
1>  Determining projects to restore...
1>  Processing application code
1>  Computing application closure and generating interop code
1>    Loading 50 modules...
1>    Generating code...
1>    Interop code generated.
1>  Compiling interop code
1>  Generating System.Reflection.DispatchProxy proxy code.
1>  Cleaning up unreferenced code
1>  Generating native code
1>  Generating fixups for native code
2>------ Build started: Project: Package, Configuration: Release x64 ------
2>Running [C:\Users\william.welsh\.nuget\packages\microsoft.javascript.hermes\0.1.18\tools\native\release\x86\hermes.exe -emit-binary -out C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle.hbc C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle -O -output-source-map] to precompile bundle file.
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,1): error G56F8712A: Invalid UTF-8 continuation byte
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,1): error GCF657EDE: unrecognized Unicode character \ufffd
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,2): error G2A165EF7: unrecognized Unicode character \u1f
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,3): error G4B4867E8: Invalid UTF-8 lead byte 0xbc
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,3): error GCF657EDE: unrecognized Unicode character \ufffd
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,4): error GFCD67ACB: unrecognized Unicode character \u3
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,5): error G56F8712A: Invalid UTF-8 continuation byte
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,5): error GCF657EDE: unrecognized Unicode character \ufffd
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,6): error GFCD67ACB: unrecognized Unicode character \u3
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,7): error G2A165EBE: unrecognized Unicode character \u19
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,8): error G2A165EF7: unrecognized Unicode character \u1f
2>���^
2>C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle(1,9): error G5BE2CDEF: invalid expression
2>���^
2>C:\Users\william.welsh\Downloads\test\node_modules\react-native-windows\PropertySheets\Bundle.Common.targets(22,5): error MSB3073: The command "C:\Users\william.welsh\.nuget\packages\microsoft.javascript.hermes\0.1.18\tools\native\release\x86\hermes.exe -emit-binary -out "C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle.hbc" "C:\Users\william.welsh\Downloads\test\windows\test\Bundle\index.windows.bundle" -O -output-source-map" exited with code 2.
2>Done building project "test.csproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 6 up-to-date, 0 skipped ==========
========== Build completed at 10:23 AM and took 52.666 seconds ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
========== Deploy completed at 10:23 AM and took 52.666 seconds ==========

Steps To Reproduce

Initialize RN project

  1. npx react-native@latest init test

Initialize RN Windows 2. cd test 3. npx react-native-windows-init --overwrite --language cs

Get it running 4. npx react-native run-windows

Try out Release mode 5. npx react-native run-windows --release

Running in x64 release runs perfectly. UseHermes is true by default now.

Set up packaged project 6. Open solution in Visual Studio 7. Add a new project - Windows Application Packaging Project (C# UWP) 8. Add the test project as a reference in the new packaging project 9. Try to run in release (setting packaged app to startup project and clicking play) 10. Fail

Expected Results

The app should run.

CLI version

12.3.2

Environment

System:
  OS: Windows 11 10.0.22631
  CPU: (20) x64 Intel(R) Core(TM) i9-10850K CPU @ 3.60GHz
  Memory: 17.89 GB / 31.87 GB
Binaries:
  Node:
    version: 20.10.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.19
    path: ~\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 10.2.3
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    AllowAllTrustedApps: Enabled
    Versions:
      - 10.0.14393.0
      - 10.0.17134.0
      - 10.0.17763.0
      - 10.0.18362.0
      - 10.0.19041.0
      - 10.0.22000.0
      - 10.0.22621.0
IDEs:
  Android Studio: Not Found
  Visual Studio:
    - 15.9.33529.398 (Visual Studio Enterprise 2017)
    - 17.5.33530.505 (Visual Studio Community 2022)
    - 17.8.34511.84 (Visual Studio Professional 2022)
    - 16.11.33529.622 (Visual Studio Community 2019)
Languages:
  Java:
    version: 17.0.8.1
    path: C:\Program Files\Eclipse Adoptium\jdk-17.0.8.101-hotspot\bin\javac.EXE
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.4
    wanted: 0.73.4
  react-native-windows:
    installed: 0.73.4
    wanted: 0.73.4
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Target Platform Version

None

Target Device(s)

Desktop

Visual Studio Version

Visual Studio 2022

Build Configuration

ReleaseBundle

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

https://github.com/WilliamWelsh/react-native-windows-hermes-fail

WilliamWelsh avatar Feb 09 '24 16:02 WilliamWelsh