Skip to content

Commit 34fe2f4

Browse files
sammooredanstepanov
authored andcommitted
fix(example): load the runtime components entry so iOS dev builds start
The root tsconfig maps react-native-css/* to ./src/*, so the example's Metro resolved react-native-css/components to src/components/index.ts, the types-only entry. Babel compiles its `export * from "react-native"` into __esModule getters, and Fast Refresh reads every one, including PushNotificationIOS. Its native module isn't linked by default, so iOS's NativeEventEmitter threw and the app crashed at startup. Redirect that resolution to src/components/index.cts, the lazy CommonJS entry the package's exports map already gives apps, and add cts to sourceExts so Metro tracks it. Published installs were never affected.
1 parent f4d18b0 commit 34fe2f4

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎example/metro.config.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@ config.resolver.nodeModulesPaths = [
1919
path.resolve(__dirname, "../node_modules"),
2020
];
2121

22+
/**
23+
* This is only required because this example app lives inside of the `react-native-css` repo.
24+
*
25+
* The root tsconfig maps `react-native-css/*` to `./src/*`, so Metro resolves
26+
* `react-native-css/components` to `src/components/index.ts`, which exists only
27+
* for types. Its `export * from "react-native"` compiles to `__esModule`
28+
* getters, and Fast Refresh reads every one of them, including
29+
* `PushNotificationIOS`, which throws on iOS. Load the runtime entry instead,
30+
* as the package's `exports` map does for apps. Metro only tracks files whose
31+
* extension is in `sourceExts`, so add `cts`; it's the only `.cts` file, and
32+
* `ts` still wins when both match.
33+
*/
34+
config.resolver.sourceExts.push("cts");
35+
const componentsTypesEntry = path.resolve(
36+
__dirname,
37+
"../src/components/index.ts",
38+
);
39+
const componentsEntry = path.resolve(__dirname, "../src/components/index.cts");
40+
config.resolver.resolveRequest = (context, moduleName, platform) => {
41+
const resolution = context.resolveRequest(context, moduleName, platform);
42+
return resolution.type === "sourceFile" &&
43+
resolution.filePath === componentsTypesEntry
44+
? { type: "sourceFile", filePath: componentsEntry }
45+
: resolution;
46+
};
47+
2248
module.exports = withReactNativeCSS(config, {
2349
globalClassNamePolyfill: true,
2450
});

0 commit comments

Comments
 (0)