@@ -16,12 +16,9 @@ config.resolver.nodeModulesPaths = [
1616 path . resolve ( monorepoRoot , "node_modules" ) ,
1717] ;
1818
19- // Force React to resolve from monorepo root, and alias workspace packages
20- // directly to their TypeScript source so Babel can transpile them (Metro
21- // does not consume the ESM `dist/` build cleanly).
19+ // Force React to resolve from monorepo root
2220config . resolver . extraNodeModules = {
2321 react : path . resolve ( monorepoRoot , "node_modules/react" ) ,
24- "@posthog/shared" : path . resolve ( monorepoRoot , "packages/shared/src/index.ts" ) ,
2522} ;
2623
2724// Apply NativeWind first so its resolver/transformer changes are in place
@@ -42,4 +39,35 @@ nativeWindConfig.resolver = {
4239 sourceExts : [ ...nativeWindConfig . resolver . sourceExts , "svg" ] ,
4340} ;
4441
42+ // Resolve @posthog /shared to its TypeScript source so Babel transpiles it.
43+ // Its package.json `exports` point at `dist/`, which is only present after a
44+ // `pnpm build` -- EAS Build never runs one, so bundling there fails outright.
45+ // This must be a resolveRequest hook rather than an `extraNodeModules` alias:
46+ // pnpm symlinks the package into node_modules, so Metro resolves it there
47+ // first and never consults the alias, and an alias also cannot map subpath
48+ // imports like `@posthog/shared/domain-types`.
49+ const SHARED_PACKAGE = "@posthog/shared" ;
50+ const sharedSrc = path . resolve ( monorepoRoot , "packages/shared/src" ) ;
51+ const upstreamResolveRequest = nativeWindConfig . resolver . resolveRequest ;
52+
53+ nativeWindConfig . resolver . resolveRequest = ( context , moduleName , platform ) => {
54+ if (
55+ moduleName === SHARED_PACKAGE ||
56+ moduleName . startsWith ( `${ SHARED_PACKAGE } /` )
57+ ) {
58+ const subpath = moduleName . slice ( SHARED_PACKAGE . length + 1 ) || "index" ;
59+ return context . resolveRequest (
60+ context ,
61+ path . join ( sharedSrc , subpath ) ,
62+ platform ,
63+ ) ;
64+ }
65+
66+ return ( upstreamResolveRequest ?? context . resolveRequest ) (
67+ context ,
68+ moduleName ,
69+ platform ,
70+ ) ;
71+ } ;
72+
4573module . exports = nativeWindConfig ;
0 commit comments