Commit b8d50a9
Fix Hermes bytecode version mismatch in SwiftPM Release builds (#57928)
Summary:
`react-native spm add`'s Release builds crash on launch with:
```
Compiling JS failed: Wrong bytecode version. Expected 99 but got 98
```
This happens because the SwiftPM integration resolves the Hermes **runtime**
(the downloaded `hermes-engine.xcframework`) and the Hermes **compiler** (the
`hermesc` binary that turns the JS bundle into bytecode) from two independent,
unsynced sources:
- `download-spm-artifacts.js`'s `resolveHermesArtifact()` picked the runtime
by querying the `hermes-compiler` package's `latest-v1` dist-tag on the npm
registry **live, at build time**.
- `generate-spm-xcodeproj.js`'s `resolveHermesCliPathSetting()` (and
`react-native-xcode.sh`, for the CocoaPods-free fallback) points
`HERMES_CLI_PATH` at the `hermes-compiler` package **already installed in
this project's own `node_modules`** — whatever got pinned the last time
`npm install` ran.
If the `latest-v1` dist-tag advances on npm between `npm install` and the
Release build (which happens routinely as new Hermes builds are published),
the downloaded VM and the locally pinned `hermesc` fall out of sync and the
app crashes at launch. `react-native-xcode.sh` already documents this exact
invariant ("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 pinned `hermes-compiler`
version from `node_modules` first (the same `require.resolve` lookup already
used for `HERMES_CLI_PATH`), so the runtime download and the compiler always
agree. It falls back to the previous `latest-v1` npm lookup only when
`hermes-compiler` isn't locally resolvable (e.g. `USE_HERMES=false` apps that
never installed it). Explicit `HERMES_VERSION` overrides (`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
Pull Request resolved: #57928
Test Plan:
Added unit tests covering the new local-resolution path, the fallback when
`hermes-compiler` isn't installed, and confirming existing `HERMES_VERSION`
overrides still take precedence over the local pin.
```
$ node_modules/.bin/jest packages/react-native/scripts/spm/__tests__/download-spm-artifacts-test.js
Test Suites: 1 passed, 1 total
Tests: 70 passed, 70 total
$ node_modules/.bin/flow check packages/react-native/scripts/spm/download-spm-artifacts.js
No errors!
$ node_modules/.bin/eslint packages/react-native/scripts/spm/download-spm-artifacts.js packages/react-native/scripts/spm/__tests__/download-spm-artifacts-test.js
(no output — clean)
$ node_modules/.bin/prettier --check packages/react-native/scripts/spm/download-spm-artifacts.js packages/react-native/scripts/spm/__tests__/download-spm-artifacts-test.js
All matched files use Prettier code style!
```
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):
- Before the fix: `npm run reproduce` builds successfully but launching the
app in the iOS Simulator crashes with `Compiling JS failed: Wrong bytecode
version. Expected 99 but got 98`.
- After applying the equivalent fix to the reproducer's installed
`react-native` copy: the log shows `Using locally pinned hermes-compiler:
250829098.0.16`, and both the debug and release Hermes runtime artifacts
resolve to that exact version — matching the `hermesc` used for
`HERMES_CLI_PATH`. `xcodebuild ... -configuration Release` succeeds, and
the app installs and launches cleanly on an iPhone 17 Pro (iOS 26.5)
simulator with no crash.
Reviewed By: cortinico
Differential Revision: D115859923
Pulled By: cipolleschi
fbshipit-source-id: 1b65a7aa28f502374a3553c1849b8ff29b5afd101 parent c6ebb06 commit b8d50a9
2 files changed
Lines changed: 184 additions & 21 deletions
File tree
- packages/react-native/scripts/spm
- __tests__
Lines changed: 120 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
68 | 130 | | |
69 | 131 | | |
70 | 132 | | |
| |||
82 | 144 | | |
83 | 145 | | |
84 | 146 | | |
| 147 | + | |
85 | 148 | | |
86 | 149 | | |
87 | 150 | | |
| |||
92 | 155 | | |
93 | 156 | | |
94 | 157 | | |
95 | | - | |
| 158 | + | |
| 159 | + | |
96 | 160 | | |
97 | | - | |
98 | | - | |
99 | | - | |
| 161 | + | |
100 | 162 | | |
101 | 163 | | |
102 | 164 | | |
103 | 165 | | |
104 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
105 | 175 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | 176 | | |
111 | 177 | | |
112 | 178 | | |
| 179 | + | |
113 | 180 | | |
114 | | - | |
115 | | - | |
| 181 | + | |
116 | 182 | | |
117 | 183 | | |
118 | | - | |
| 184 | + | |
119 | 185 | | |
120 | 186 | | |
121 | 187 | | |
122 | 188 | | |
| 189 | + | |
123 | 190 | | |
124 | | - | |
| 191 | + | |
125 | 192 | | |
126 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
127 | 220 | | |
128 | 221 | | |
129 | 222 | | |
130 | | - | |
| 223 | + | |
131 | 224 | | |
| 225 | + | |
132 | 226 | | |
133 | 227 | | |
134 | 228 | | |
135 | 229 | | |
136 | 230 | | |
137 | 231 | | |
138 | 232 | | |
| 233 | + | |
139 | 234 | | |
140 | 235 | | |
141 | 236 | | |
142 | 237 | | |
143 | 238 | | |
144 | | - | |
| 239 | + | |
145 | 240 | | |
| 241 | + | |
146 | 242 | | |
147 | 243 | | |
148 | 244 | | |
| |||
151 | 247 | | |
152 | 248 | | |
153 | 249 | | |
| 250 | + | |
154 | 251 | | |
155 | 252 | | |
156 | 253 | | |
157 | 254 | | |
158 | 255 | | |
159 | 256 | | |
| 257 | + | |
160 | 258 | | |
161 | 259 | | |
162 | 260 | | |
| |||
167 | 265 | | |
168 | 266 | | |
169 | 267 | | |
| 268 | + | |
170 | 269 | | |
171 | 270 | | |
172 | 271 | | |
173 | 272 | | |
174 | 273 | | |
175 | 274 | | |
| 275 | + | |
176 | 276 | | |
177 | 277 | | |
178 | 278 | | |
| |||
185 | 285 | | |
186 | 286 | | |
187 | 287 | | |
188 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
189 | 294 | | |
190 | 295 | | |
191 | 296 | | |
| |||
Lines changed: 64 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
396 | 434 | | |
397 | 435 | | |
398 | 436 | | |
399 | 437 | | |
400 | | - | |
401 | | - | |
| 438 | + | |
402 | 439 | | |
403 | | - | |
404 | | - | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
405 | 453 | | |
406 | 454 | | |
407 | 455 | | |
| |||
413 | 461 | | |
414 | 462 | | |
415 | 463 | | |
| 464 | + | |
416 | 465 | | |
417 | | - | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
418 | 475 | | |
419 | 476 | | |
420 | 477 | | |
| |||
1119 | 1176 | | |
1120 | 1177 | | |
1121 | 1178 | | |
1122 | | - | |
| 1179 | + | |
1123 | 1180 | | |
1124 | 1181 | | |
1125 | 1182 | | |
| |||
1390 | 1447 | | |
1391 | 1448 | | |
1392 | 1449 | | |
| 1450 | + | |
1393 | 1451 | | |
1394 | 1452 | | |
1395 | 1453 | | |
| |||
0 commit comments