Skip to content

[ERR_UNSUPPORTED_ESM_URL_SCHEME] loadConfig.js cannot process file:// absolute paths #285166

Description

@SharonNg98

Type: Bug

I am using npx expo start to process one of the many functions, i.e., ImageSourcePropType from Expo. The format for this is { uri: C:\Users\... }. However, I kept on getting

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Error loading Metro config at: C:\Users\${DIR_NAME}\metro.config.js
Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'

I have changed the config in node_modules\metro-config\src\loadConfig.js like this:

Instead of

const configModule = await import(absolutePath);
put

// Fix for Windows: convert Windows path to file:// URL for dynamic import
const pathToImport = path.isAbsolute(absolutePath) && process.platform === 'win32'
  ? (0, _url.pathToFileURL)(absolutePath).href
  : absolutePath;
const configModule = await import(pathToImport);
config = await configModule.default;

However, the terminal still doesn't work. This worked for other users but not mine.
npx expo start previously worked when I incorrectly used require(). Please advise.

VS Code version: Code 1.107.1
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz (8 x 2395)
GPU Status 2d_canvas: enabled
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
trees_in_viz: disabled_off
video_decode: enabled
video_encode: unavailable_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off

Metadata

Metadata

Labels

info-neededIssue requires more information from poster

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions