Repository navigation
Description
Currently, we look up the appropriate version of hermes from react-native like so:
react-native-node-api/packages/host/src/node/cli/hermes.ts
Lines 31 to 38 in 0419678
| const appPackageRoot = packageDirectorySync({ cwd: from }); | |
| assert(appPackageRoot, "Failed to find package root"); | |
| const reactNativePath = path.dirname( | |
| require.resolve("react-native/package.json", { | |
| // Ensures we'll be patching the React Native package actually used by the app | |
| paths: [appPackageRoot], | |
| }), | |
| ); |
For out-of-tree platforms like react-native-macos, though, I had to apply the following patch before it'd resolve the correct root during pod install:
let reactNativePath;
if(from.endsWith("ios") || from.endsWith("android")){
reactNativePath = node_path_1.default.dirname(require.resolve("react-native/package.json", {
// Ensures we'll be patching the React Native package actually used by the app
paths: [appPackageRoot],
}));
} else if(from.endsWith("macos")){
reactNativePath = node_path_1.default.dirname(require.resolve("react-native-macos/package.json", {
// Ensures we'll be patching the React Native package actually used by the app
paths: [appPackageRoot],
}));
} else if(from.endsWith("windows")){
reactNativePath = node_path_1.default.dirname(require.resolve("react-native-windows/package.json", {
// Ensures we'll be patching the React Native package actually used by the app
paths: [appPackageRoot],
}));
} else {
throw new Error("Unsupported platform.");
}There is surely a more elegant way to do it (it would be nicest to know the platform for certain, rather than just guessing based on the presence of an ios/android/macos folder in the path), but just to illustrate the point.
Reacted by Kræn Hansen
Metadata
Metadata
Assignees
Labels
No labels
Activity
kraenhansen commentedon Oct 23, 2025
Another issue here is that we download the Hermes fork into the host package (
node_modules/react-native-node-api/hermes) and assume there will be a single version needed. Perhaps we should download it into thereact-nativepackage (orreact-native-macos/react-native-windows) instead? 🤔I've put up a #287 as a suggestion - let me know what you think 🙂
kraenhansen commentedon Oct 26, 2025
Reopening the issue, since we'd like to detect the relevant
--react-native-package, either in scripts/patch-hermes.rb or as part of computing a default value inside the CLI.