Skip to content

Commit f7ca003

Browse files
committed
fix: Add runtime error when Metro config cannot be resolved
1 parent 917f1bf commit f7ca003

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/cli-plugin-metro/src/tools/loadMetroConfig.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path';
2-
import {ConfigT, InputConfigT, loadConfig} from 'metro-config';
2+
import {ConfigT, InputConfigT, loadConfig, resolveConfig} from 'metro-config';
33
import type {Config} from '@react-native-community/cli-types';
44
import {reactNativePlatformResolver} from './metroPlatformResolver';
55

@@ -69,13 +69,21 @@ export interface ConfigOptionsT {
6969
* Allows the CLI to override certain defaults in the base `metro.config.js`
7070
* based on dynamic user options in `ctx`.
7171
*/
72-
export default function loadMetroConfig(
72+
export default async function loadMetroConfig(
7373
ctx: ConfigLoadingContext,
74-
options?: ConfigOptionsT,
74+
options: ConfigOptionsT = {},
7575
): Promise<ConfigT> {
7676
const overrideConfig = getOverrideConfig(ctx);
77-
if (options && options.reporter) {
77+
if (options.reporter) {
7878
overrideConfig.reporter = options.reporter;
7979
}
80+
81+
const projectConfig = await resolveConfig(undefined, ctx.root);
82+
83+
// @ts-ignore resolveConfig return value is mistyped
84+
if (projectConfig.isEmpty) {
85+
throw new Error(`No metro config found in ${ctx.root}`);
86+
}
87+
8088
return loadConfig({cwd: ctx.root, ...options}, overrideConfig);
8189
}

0 commit comments

Comments
 (0)