Skip to content

Commit

Permalink
fix: resolver.resolveRequest is always undefined (#1982)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed authored and thymikee committed Jun 22, 2023
1 parent 92bbda9 commit 1539fcd
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/cli-plugin-metro/src/tools/loadMetroConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
loadConfig,
mergeConfig,
resolveConfig,
ResolverConfigT,
} from 'metro-config';
import {CLIError, logger} from '@react-native-community/cli-tools';
import type {Config} from '@react-native-community/cli-types';
Expand All @@ -26,23 +27,24 @@ function getOverrideConfig(ctx: ConfigLoadingContext): InputConfigT {
const outOfTreePlatforms = Object.keys(ctx.platforms).filter(
(platform) => ctx.platforms[platform].npmPackageName,
);
const resolver: Partial<ResolverConfigT> = {
platforms: [...Object.keys(ctx.platforms), 'native'],
};

if (outOfTreePlatforms.length) {
resolver.resolveRequest = reactNativePlatformResolver(
outOfTreePlatforms.reduce<{[platform: string]: string}>(
(result, platform) => {
result[platform] = ctx.platforms[platform].npmPackageName!;
return result;
},
{},
),
);
}

return {
resolver: {
resolveRequest:
outOfTreePlatforms.length === 0
? undefined
: reactNativePlatformResolver(
outOfTreePlatforms.reduce<{[platform: string]: string}>(
(result, platform) => {
result[platform] = ctx.platforms[platform].npmPackageName!;
return result;
},
{},
),
),
platforms: [...Object.keys(ctx.platforms), 'native'],
},
resolver,
serializer: {
// We can include multiple copies of InitializeCore here because metro will
// only add ones that are already part of the bundle
Expand Down

0 comments on commit 1539fcd

Please sign in to comment.