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:
- Removed
node_modules
- Removed
pnpm-lock.yaml
- Reinstalled dependencies
- 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
ReferenceError: __filename is not definedwhen using latest@module-federation/modern-js-v3Description
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:
This appears to happen inside the
@module-federation/modern-js-v3package, specifically around the usage ofcreateJiti(__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 definedSteps Tried
I have already tried the following:
node_modulespnpm-lock.yaml@module-federation/modern-js-v3is being usedUnfortunately, 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
__filenameis not available in the ESM context.Additional Context
Since the error occurs in an
.mjsfile, it seems that__filenameis 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