Skip to content

Conversation

@ha1fstack
Copy link

@ha1fstack ha1fstack commented Dec 11, 2025

closes #155

Problem

Yarn PnP can not resolve arbitary qualified resolutions (or packages) whose are not declared explicitly.

However this plugin relies on on-the-fly generated __mf__virtual package inside physical node_modules folder - so it was not compatible

Tries

I first tried to use Vite's virtual module (in-memory) instead of real fs. But it did not work well since this plugin seems to be relying on (the intend is not documented so this is a guess) Vite's dependency pre-bundling - but virtual modules cannot be pre-bundled.

Solution

The root cause was not fs, so I focused on the qualified / unqualified resolution part. Instead of making the generated code as a package (with package.json and importing it with name), using unqualified resolution (real path) + creating alias to that path to keep things simple solved the issue.

Also fixed the problematic searchPackageVersion util too since the packages needs to be resolved from the host package (the service) root not the vite-mf's package root.

Comment on lines +16 to 22
const targetRoot = rootDir || process.cwd();
const nodeModulesPath = join(targetRoot, 'node_modules');
if (!existsSync(nodeModulesPath)) {
mkdirSync(nodeModulesPath, { recursive: true });
}
cachedNodeModulesDir = nodeModulesPath;
return cachedNodeModulesDir;
Copy link
Author

Choose a reason for hiding this comment

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

We are using vite project's root instead of traversing for existing folder because pnp doesn't generate node_modules and this seems more natural

Copy link
Collaborator

@gioboa gioboa Dec 24, 2025

Choose a reason for hiding this comment

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

I see, I'm not sure if this is working on monorepo projects. cc @Xeikim you added this fix long time ago for monorepos.

Copy link
Author

@ha1fstack ha1fstack Dec 25, 2025

Choose a reason for hiding this comment

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

The original problem was that rootDir find traversal was using process.cwd not the actual vite project's root
We are still using vite's project rootDir (fixed by #256) but only omitting the traversal part - so it seems fine to me.

@ha1fstack ha1fstack changed the title feat: pnp support feat: Yarn PnP support Dec 11, 2025
@ha1fstack ha1fstack marked this pull request as ready for review December 11, 2025 07:01
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.

Thanks for your contribution @ha1fstack
Unfortunately, in these days I'm quite busy and I can't review the PR as fast as I usually do.
I'm going to look at it in the next days.

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.

Yarn support: Yarn PnP can't find __mf__virtual

2 participants