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, });