Skip to content

fix: create shared virtual module files early for build mode to prevent ENOENT on cold CI builds#459

Draft
yashnextgenit1-design wants to merge 6 commits intomodule-federation:mainfrom
yashnextgenit1-design:fix/ci-enoent-build-error-cold-start
Draft

fix: create shared virtual module files early for build mode to prevent ENOENT on cold CI builds#459
yashnextgenit1-design wants to merge 6 commits intomodule-federation:mainfrom
yashnextgenit1-design:fix/ci-enoent-build-error-cold-start

Conversation

@yashnextgenit1-design
Copy link
Contributor

Summary:

The first vite build in a clean CI environment (fresh node_modules) fails with ENOENT when @rollup/plugin-commonjs tries to load prebuild virtual module files from node_modules/__mf__virtual/. Retrying the same build succeeds because files persist from the failed attempt.

Root Cause:

In createEarlyVirtualModulesPlugin shared virtual module files (prebuild .js, loadShare .mjs) were only created in the

config hook for serve mode. For build mode, file creation was deferred to proxyPreBuildShared.configResolved which has enforce: 'post'.

Vite executes
configResolved hooks in order: pre → normal → post. This means Vite's internal plugins and @rollup/plugin-commonjs run their

configResolved before proxyPreBuildShared writes the virtual files. On a cold build the __mf__virtual directory only contains empty.js and

package.json at that point — the prebuild files don't exist yet, causing ENOENT when Rollup later tries to load them.

On retry, files written during the failed first build already exist on disk, so everything works.

Fix

Removed the if (_command !== 'serve') return; guard so that writeLoadShareModule, writePreBuildLibPath, and related calls now execute in the

config hook (which runs before all configResolved hooks) for both serve and build commands. Only the optimizeDeps.include configuration remains gated behind serve mode, as it is only relevant for the dev server.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 10, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@module-federation/vite@459

commit: ba9aff2

Copy link
Collaborator

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check this release npm i https://pkg.pr.new/@module-federation/vite@459 🙏
Thanks for your commitment @yashnextgenit1-design

@yashnextgenit1-design yashnextgenit1-design marked this pull request as draft March 10, 2026 09:47
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.

2 participants