Skip to content

Commit acb5d05

Browse files
Use a module request for asyncRequireModulePath so Metro's transform cache is shareable across checkouts
@react-native/metro-config set asyncRequireModulePath with require.resolve(), which embeds the absolute path of the checkout in Metro's global transform cache key. Two checkouts of the same project (git worktrees, CI workspaces) never shared a transform cache entry. Use the bare specifier, matching Metro's own default and @expo/metro-config, with an extraNodeModules fallback so it still resolves in installs where metro-runtime is not reachable from every module (pnpm isolated).
1 parent d2a6ce5 commit acb5d05

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎packages/metro-config/src/index.flow.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import type {ConfigT, InputConfigT} from 'metro-config';
1212

1313
import {getDefaultConfig as getBaseConfig, mergeConfig} from 'metro-config';
14+
import path from 'node:path';
1415

1516
export type {MetroConfig} from 'metro-config';
1617

@@ -57,6 +58,14 @@ export function getDefaultConfig(projectRoot: string): ConfigT {
5758
resolverMainFields: ['react-native', 'browser', 'main'],
5859
platforms: ['android', 'ios'],
5960
unstable_conditionNames: ['react-native'],
61+
// Lets transformer.asyncRequireModulePath stay a module request, which
62+
// keeps it out of the transform cache key, in installs where
63+
// metro-runtime is not reachable from every module (pnpm isolated).
64+
extraNodeModules: {
65+
'metro-runtime': path.dirname(
66+
require.resolve('metro-runtime/package.json'),
67+
),
68+
},
6069
},
6170
serializer: {
6271
// NOTE: Overridden in community-cli-plugin
@@ -85,8 +94,7 @@ export function getDefaultConfig(projectRoot: string): ConfigT {
8594
transformer: {
8695
allowOptionalDependencies: true,
8796
assetRegistryPath: 'react-native/asset-registry',
88-
asyncRequireModulePath:
89-
require.resolve('metro-runtime/src/modules/asyncRequire'),
97+
asyncRequireModulePath: 'metro-runtime/src/modules/asyncRequire',
9098
babelTransformerPath:
9199
require.resolve('@react-native/metro-babel-transformer'),
92100
getTransformOptions: async () => ({

0 commit comments

Comments
 (0)