Skip to content

__filename is not defined #4805

Description

@casad1as

ReferenceError: __filename is not defined when using latest @module-federation/modern-js-v3

Description

I am encountering a runtime error when starting a Modern.js application that uses the latest version of @module-federation/modern-js-v3.

The error is:

ReferenceError: __filename is not defined

This appears to happen inside the @module-federation/modern-js-v3 package, specifically around the usage of createJiti(__filename, ...).

I noticed that a related fix was merged in this PR:

#4784

However, the issue still persists after upgrading to the latest available version.

Error Output

file:///.../node_modules/@module-federation/modern-js-v3/dist/esm/cli/configPlugin.mjs:69
  jit = createJiti(__filename, {
                   ^

ReferenceError: __filename is not defined

Steps Tried

I have already tried the following:

  1. Removed node_modules
  2. Removed pnpm-lock.yaml
  3. Reinstalled dependencies
  4. Confirmed that the latest available version of @module-federation/modern-js-v3 is being used

Unfortunately, the same error still occurs.

Expected Behavior

The Modern.js dev server should start successfully without throwing a ReferenceError.

Actual Behavior

The dev server fails during startup because __filename is not available in the ESM context.

Additional Context

Since the error occurs in an .mjs file, it seems that __filename is still being referenced in an ESM environment where it is not defined by default.

Could you please confirm whether the fix from PR #4784 has been included in the latest published package version, or whether another release is needed?

Reproduction

Used Package Manager

pnpm

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (12) x64 AMD Ryzen 5 5600 6-Core Processor
    Memory: 4.17 GB / 15.93 GB
  Binaries:
    Node: 22.22.3 - C:\nvm4w\nodejs\node.EXE
    npm: 10.9.8 - C:\nvm4w\nodejs\npm.CMD
    pnpm: 10.34.1 - C:\nvm4w\nodejs\pnpm.CMD
  Browsers:
    Chrome: 149.0.7827.53
    Edge: Chromium (148.0.3967.83)

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions