Title: rspack/webpack virtual modules can't do relative import · Issue #483 · unjs/unplugin · GitHub
Open Graph Title: rspack/webpack virtual modules can't do relative import · Issue #483 · unjs/unplugin
X Title: rspack/webpack virtual modules can't do relative import · Issue #483 · unjs/unplugin
Description: Environment unplugin@2.2.2 Node 23.4.0 Windows 11 version 10.0.26100 Build 26100 Reproduction Repo: https://github.com/edemaine/unplugin-rspack-relative-import Run: npm install npm run build Error: > rspack@1.0.0 build > rspack build ERR...
Open Graph Description: Environment unplugin@2.2.2 Node 23.4.0 Windows 11 version 10.0.26100 Build 26100 Reproduction Repo: https://github.com/edemaine/unplugin-rspack-relative-import Run: npm install npm run build Error:...
X Description: Environment unplugin@2.2.2 Node 23.4.0 Windows 11 version 10.0.26100 Build 26100 Reproduction Repo: https://github.com/edemaine/unplugin-rspack-relative-import Run: npm install npm run build Error:...
Opengraph URL: https://github.com/unjs/unplugin/issues/483
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"rspack/webpack virtual modules can't do relative import","articleBody":"### Environment\n\nunplugin@2.2.2\nNode 23.4.0\nWindows 11 version 10.0.26100 Build 26100\n\n### Reproduction\n\nRepo: https://github.com/edemaine/unplugin-rspack-relative-import\nRun:\n* `npm install`\n* `npm run build`\n\nError:\n\n```\n> rspack@1.0.0 build\n> rspack build\n\nERROR in ./node_modules/.virtual/C%3A%5CUsers%5Cedemaine%5CProjects%5Cunplugin-rspack-relative-import%5Csrc%5Cindex.civet.jsx 1:0-21\n × Module not found: Can't resolve './index.css' in 'C:\\Users\\edemaine\\Projects\\unplugin-rspack-relative-import\\node_modules\\.virtual'\n ╭─[1:7]\n 1 │ import \"./index.css\";\n · ─────────────\n 2 │\n 3 │ document.querySelector(\"#root\").innerHTML = `\n ╰────\n```\n\n### Describe the bug\n\nFrom #416 I gather that webpack/rspack virtual modules get put inside `node_modules/.virtual`. Then the relative import of `./index.css` is getting resolved within that directory, which fails.\n\n### Additional context\n\nI tried logging calls to `resolveId`, and I see the following:\n```\nresolveId(\"./src/index.civet\", undefined)\nresolveId(\"./index.css\", \"\\C:\\Users\\edemaine\\Projects\\Civet\\integration\\unplugin-examples\\rspack\\src\\index.civet.jsx\")\n```\n\nThis suggest to me that the virtual prefix is getting stripped incorrectly on Windows; I don't think the leading `\\` should be there. #421 might be the same issue, and #422 might fix this.\n\nBut I don't think that this is the cause for this particular bug. rspack itself isn't going to strip virtual module names; only unplugin will. So rspack is going to resolve relative paths incorrectly, unless they're handled by an unplugin. I'd rather not have my unplugin help resolve all files, only the ones it's supposed to do (`.civet`).\n\nI guess the workaround is for my unplugin's `resolveId` to fix the paths for all imports, perhaps when the `importer` is recognized as something my unplugin generated.\n\nI *think* a better fix would be to put virtual modules in the same directory as the source file. I understand that the `node_modules/.virtual` choice was made to avoid it appearing in VSCode or Git. But I don't see how relative imports could work in this scenario.\n\nLet me know what you think and I can try to work on a fix.\n","author":{"url":"https://github.com/edemaine","@type":"Person","name":"edemaine"},"datePublished":"2025-03-23T15:30:59Z","url":"https://github.com/unjs/unplugin/issues/483"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f6a4c3ec-79cf-4383-7edd-e5dd85882175 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9274:2E5D6B:592311:7972CE:6B00744D |
| html-safe-nonce | 6e9a32b59c3afad4ed646c745c2f9246ff17a410da08c53119bc16298a059547 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Mjc0OjJFNUQ2Qjo1OTIzMTE6Nzk3MkNFOjZCMDA3NDREIiwidmlzaXRvcl9pZCI6IjMyNjQwMTM0MzY5NDE1MzAxODkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5cd670cc6a7d90a27d33f8b1dd5205da25690f7b2bb722779883efb643da46e8 |
| hovercard-subject-tag | issue:2941265981 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/unjs/unplugin/483/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5b218deca7573cc683428899f695f114662f4b0921aceb4885a0871b9901bf97/unjs/unplugin/issues/483 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5b218deca7573cc683428899f695f114662f4b0921aceb4885a0871b9901bf97/unjs/unplugin/issues/483 |
| og:image:alt | Environment unplugin@2.2.2 Node 23.4.0 Windows 11 version 10.0.26100 Build 26100 Reproduction Repo: https://github.com/edemaine/unplugin-rspack-relative-import Run: npm install npm run build Error:... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | edemaine |
| hostname | github.com |
| expected-hostname | github.com |
| None | 75c2b65dd205f26961d0c29afed1a8d0bb7cca9f05780571dfd1ef93eb539d16 |
| turbo-cache-control | no-preview |
| go-import | github.com/unjs/unplugin git https://github.com/unjs/unplugin.git |
| octolytics-dimension-user_id | 80154025 |
| octolytics-dimension-user_login | unjs |
| octolytics-dimension-repository_id | 385261169 |
| octolytics-dimension-repository_nwo | unjs/unplugin |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 385261169 |
| octolytics-dimension-repository_network_root_nwo | unjs/unplugin |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 84e563eb4b55f8fa102f325f117533cee9e3df4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width