Skip to content

Fix ESM compatibility in Metro project path resolution - #1869

Open
rklomp wants to merge 1 commit into
akveo:nextfrom
rklomp:patch-3
Open

Fix ESM compatibility in Metro project path resolution#1869
rklomp wants to merge 1 commit into
akveo:nextfrom
rklomp:patch-3

Conversation

@rklomp

@rklomp rklomp commented Aug 15, 2026

Copy link
Copy Markdown

Please read and mark the following check list before creating a pull request:

Short description of what this resolves:

Fixes an __dirname is not defined runtime error in the ESM build of @ui-kitten/metro-config.

@ui-kitten/metro-config is distributed with an ESM build, but project.service.js uses the CommonJS-specific __dirname global:

const PROJECT_PATH = Path.resolve(__dirname, '../../../../');

When the ESM build is loaded by modern Node.js versions, __dirname is not defined and Metro configuration fails to initialize:

ReferenceError: __dirname is not defined in ES module scope

Derive __dirname from import.meta.url using Node's standard ESM-compatible APIs:

const __filename = fileURLToPath(import.meta.url);
const __dirname = Path.dirname(__filename);

This preserves the existing path resolution while making the ESM build compatible with Node.js ESM semantics and Windows path handling.

Tested with:
Expo 57
React Native 0.86
Node.js 22
Windows

The Metro configuration successfully initializes after applying this change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant