Skip to content

Conversation

@joshuaellis
Copy link

Description

When using @module-federation/vite with pnpm (strict mode, no shameful hoisting), the dev server fails with:

Failed to resolve import "@module-federation/dts-plugin/dynamic-remote-type-hints-plugin" from "virtual:mf-REMOTE_ENTRY_ID". Does the file exist?                                                                                                                                                            

This fix intercepts imports originating from the virtual remote entry and re-resolves them from this package's own location, where the transitive dependencies are available.

Notes

There weren't any unit tests nor e2e tests that I could write to be more confident in the change other than running on my local instance – open to suggestions though.

Comment on lines +43 to +52
if (
importer === REMOTE_ENTRY_ID &&
!id.startsWith('.') &&
!id.startsWith('/') &&
!id.startsWith('\0') &&
!id.startsWith('virtual:')
) {
const resolved = await this.resolve(id, __filename, { skipSelf: true });
if (resolved) return resolved;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks great to me 👏 Thanks @joshuaellis

I double checked with AI and __filename is CJS-only, in ESM we can use fileURLToPath(import.meta.url)

Let's add a fallback

const importerPath = typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url);
const resolved = await this.resolve(id, importerPath, { skipSelf: true });
if (resolved) return resolved;

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.

That's awesome 👍
I added a small comment.

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