Fix Hermes bytecode version mismatch in SwiftPM Release builds - #57928
Open
nduaarte wants to merge 1 commit into
Open
Fix Hermes bytecode version mismatch in SwiftPM Release builds#57928nduaarte wants to merge 1 commit into
nduaarte wants to merge 1 commit into
Conversation
download-spm-artifacts.js picked the Hermes runtime xcframework by querying the hermes-compiler npm package's latest-v1 dist-tag live, at build time. generate-spm-xcodeproj.js's HERMES_CLI_PATH resolution (and react-native-xcode.sh's SwiftPM fallback) instead point at the hermes-compiler package already pinned in the project's own node_modules. When the live dist-tag advances between `npm install` and a Release build, the two disagree and the app crashes at launch with "Wrong bytecode version". Make resolveHermesArtifact() read the pinned hermes-compiler version from node_modules first, falling back to the latest-v1 lookup only when the package isn't locally resolvable. Fixes react#57917. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
react-native spm add's Release builds crash on launch with:This happens because the SwiftPM integration resolves the Hermes runtime
(the downloaded
hermes-engine.xcframework) and the Hermes compiler (thehermescbinary that turns the JS bundle into bytecode) from two independent,unsynced sources:
download-spm-artifacts.js'sresolveHermesArtifact()picked the runtimeby querying the
hermes-compilerpackage'slatest-v1dist-tag on the npmregistry live, at build time.
generate-spm-xcodeproj.js'sresolveHermesCliPathSetting()(andreact-native-xcode.sh, for the CocoaPods-free fallback) pointsHERMES_CLI_PATHat thehermes-compilerpackage already installed inthis project's own
node_modules— whatever got pinned the last timenpm installran.If the
latest-v1dist-tag advances on npm betweennpm installand theRelease build (which happens routinely as new Hermes builds are published),
the downloaded VM and the locally pinned
hermescfall out of sync and theapp crashes at launch.
react-native-xcode.shalready documents this exactinvariant ("react native pins the hermes-compiler version, so the compiler's
bytecode version always matches the prebuilt hermes VM artifacts") — SwiftPM's
artifact download just wasn't honoring it.
This PR makes
resolveHermesArtifact()read the pinnedhermes-compilerversion from
node_modulesfirst (the samerequire.resolvelookup alreadyused for
HERMES_CLI_PATH), so the runtime download and the compiler alwaysagree. It falls back to the previous
latest-v1npm lookup only whenhermes-compilerisn't locally resolvable (e.g.USE_HERMES=falseapps thatnever installed it). Explicit
HERMES_VERSIONoverrides (nightly,latest-v1, a literal version) are unchanged.Fixes #57917.
Changelog:
[IOS] [FIXED] - Fix Hermes runtime/compiler version mismatch causing "Wrong bytecode version" crashes in SwiftPM Release builds
Test Plan:
Added unit tests covering the new local-resolution path, the fallback when
hermes-compilerisn't installed, and confirming existingHERMES_VERSIONoverrides still take precedence over the local pin.
Reproduced the crash and confirmed the fix end-to-end using the public
reproducer linked from the issue
(https://github.com/marandaneto/react-native-087-swiftpm-hermes-bytecode-repro):
npm run reproducebuilds successfully but launching theapp in the iOS Simulator crashes with
Compiling JS failed: Wrong bytecode version. Expected 99 but got 98.react-nativecopy: the log showsUsing locally pinned hermes-compiler: 250829098.0.16, and both the debug and release Hermes runtime artifactsresolve to that exact version — matching the
hermescused forHERMES_CLI_PATH.xcodebuild ... -configuration Releasesucceeds, andthe app installs and launches cleanly on an iPhone 17 Pro (iOS 26.5)
simulator with no crash.