Skip to content

rspack: concurrency issue when resolving the same virtual module #503

@elbywan

Description

@elbywan

Environment

unplugin@v2.3.0
node@v22.13.1

Reproduction

I prepared a small repo to easily repro: https://github.com/elbywan/unplugin-repro

Describe the bug

To handle virtual modules with rspack, unplugin creates a dummy file under the node_modules/.virtual folder.

But when a plugin resolves multiple virtual imports to the same path in a very short notice subsequent resolveId calls may return before the file is actually created - because they won't wait for the first resolveId to finish creating the vfs file - and it will cause the rspack resolver to complain that the file is missing.

Additional context

No response

Logs

This is the kind of error that is thrown:

ERROR in ./src/imports/7994.ts 1:0-26
  × Module not found: Can't resolve '/Users/julien.elbaz/dev/experiments/unplugin-repro/node_modules/.virtual/a%3Fvirtual' in '/Users/julien.elbaz/dev/experiments/unplugin-repro/src/imports'
   ╭────
 1 │ import a from 'a?virtual';
   ·               ───────────
   ╰────

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions