Commit ead9377
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 8804333 commit ead9377
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 | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
95 | 96 | | |
96 | 97 | | |
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 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
98 | 160 | | |
99 | 161 | | |
100 | 162 | | |
| |||
112 | 174 | | |
113 | 175 | | |
114 | 176 | | |
| 177 | + | |
115 | 178 | | |
116 | 179 | | |
117 | 180 | | |
| |||
122 | 185 | | |
123 | 186 | | |
124 | 187 | | |
125 | | - | |
| 188 | + | |
| 189 | + | |
126 | 190 | | |
127 | | - | |
128 | | - | |
129 | | - | |
| 191 | + | |
130 | 192 | | |
131 | 193 | | |
132 | 194 | | |
133 | 195 | | |
134 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
135 | 205 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | 206 | | |
141 | 207 | | |
142 | 208 | | |
| 209 | + | |
143 | 210 | | |
144 | | - | |
145 | | - | |
| 211 | + | |
146 | 212 | | |
147 | 213 | | |
148 | | - | |
| 214 | + | |
149 | 215 | | |
150 | 216 | | |
151 | 217 | | |
152 | 218 | | |
| 219 | + | |
153 | 220 | | |
154 | | - | |
| 221 | + | |
155 | 222 | | |
156 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
157 | 250 | | |
158 | 251 | | |
159 | 252 | | |
160 | | - | |
| 253 | + | |
161 | 254 | | |
| 255 | + | |
162 | 256 | | |
163 | 257 | | |
164 | 258 | | |
165 | 259 | | |
166 | 260 | | |
167 | 261 | | |
168 | 262 | | |
| 263 | + | |
169 | 264 | | |
170 | 265 | | |
171 | 266 | | |
172 | 267 | | |
173 | 268 | | |
174 | | - | |
| 269 | + | |
175 | 270 | | |
| 271 | + | |
176 | 272 | | |
177 | 273 | | |
178 | 274 | | |
| |||
181 | 277 | | |
182 | 278 | | |
183 | 279 | | |
| 280 | + | |
184 | 281 | | |
185 | 282 | | |
186 | 283 | | |
187 | 284 | | |
188 | 285 | | |
189 | 286 | | |
| 287 | + | |
190 | 288 | | |
191 | 289 | | |
192 | 290 | | |
| |||
197 | 295 | | |
198 | 296 | | |
199 | 297 | | |
| 298 | + | |
200 | 299 | | |
201 | 300 | | |
202 | 301 | | |
203 | 302 | | |
204 | 303 | | |
205 | 304 | | |
| 305 | + | |
206 | 306 | | |
207 | 307 | | |
208 | 308 | | |
| |||
215 | 315 | | |
216 | 316 | | |
217 | 317 | | |
218 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
219 | 324 | | |
220 | 325 | | |
221 | 326 | | |
| |||
Lines changed: 64 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
455 | 493 | | |
456 | 494 | | |
457 | 495 | | |
458 | 496 | | |
459 | | - | |
460 | | - | |
| 497 | + | |
461 | 498 | | |
462 | | - | |
463 | | - | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
464 | 512 | | |
465 | 513 | | |
466 | 514 | | |
| |||
472 | 520 | | |
473 | 521 | | |
474 | 522 | | |
| 523 | + | |
475 | 524 | | |
476 | | - | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
477 | 534 | | |
478 | 535 | | |
479 | 536 | | |
| |||
1178 | 1235 | | |
1179 | 1236 | | |
1180 | 1237 | | |
1181 | | - | |
| 1238 | + | |
1182 | 1239 | | |
1183 | 1240 | | |
1184 | 1241 | | |
| |||
1449 | 1506 | | |
1450 | 1507 | | |
1451 | 1508 | | |
| 1509 | + | |
1452 | 1510 | | |
1453 | 1511 | | |
1454 | 1512 | | |
| |||
0 commit comments