From 34fe2f482d9560bc1ff34a9c8af2a2e5b346f94a Mon Sep 17 00:00:00 2001 From: Sam Moore Date: Thu, 3 Dec 2026 14:43:51 -0500 Subject: [PATCH] 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. --- example/metro.config.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/example/metro.config.js b/example/metro.config.js index 9e5fa72b..9b374e7d 100644 --- a/example/metro.config.js +++ b/example/metro.config.js @@ -19,6 +19,32 @@ config.resolver.nodeModulesPaths = [ path.resolve(__dirname, "../node_modules"), ]; +/** + * This is only required because this example app lives inside of the `react-native-css` repo. + * + * The root tsconfig maps `react-native-css/*` to `./src/*`, so Metro resolves + * `react-native-css/components` to `src/components/index.ts`, which exists only + * for types. Its `export * from "react-native"` compiles to `__esModule` + * getters, and Fast Refresh reads every one of them, including + * `PushNotificationIOS`, which throws on iOS. Load the runtime entry instead, + * as the package's `exports` map does for apps. Metro only tracks files whose + * extension is in `sourceExts`, so add `cts`; it's the only `.cts` file, and + * `ts` still wins when both match. + */ +config.resolver.sourceExts.push("cts"); +const componentsTypesEntry = path.resolve( + __dirname, + "../src/components/index.ts", +); +const componentsEntry = path.resolve(__dirname, "../src/components/index.cts"); +config.resolver.resolveRequest = (context, moduleName, platform) => { + const resolution = context.resolveRequest(context, moduleName, platform); + return resolution.type === "sourceFile" && + resolution.filePath === componentsTypesEntry + ? { type: "sourceFile", filePath: componentsEntry } + : resolution; +}; + module.exports = withReactNativeCSS(config, { globalClassNamePolyfill: true, });