Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack / rspack load virtual module id with / prefix on windows caused error #421

Open
tmg0 opened this issue Sep 23, 2024 · 1 comment · May be fixed by #422
Open

webpack / rspack load virtual module id with / prefix on windows caused error #421

tmg0 opened this issue Sep 23, 2024 · 1 comment · May be fixed by #422
Labels
bug Something isn't working

Comments

@tmg0
Copy link

tmg0 commented Sep 23, 2024

Environment

Reproduction

https://github.com/tmg0/unplugin

Describe the bug

When I try to load a virtual module with / prefix on windows, id path has been converted from / to \, and this issue caused unplugin-vue-router doesn't work with rspack and webpack

I have forked this repo and modify the test file in virtual-module

// test\fixtures\virtual-module\unplugin.js
const { createUnplugin } = require('unplugin')

module.exports = createUnplugin(() => {
  return {
    name: 'virtual-module-fixture',
    resolveId(id) {
      return id.startsWith('virtual/') ? `/__${id}` : null
    },
    loadInclude(id) {
      return id.startsWith('/__virtual/')
    },
    load(id) {
      if (id === '/__virtual/1')
        return 'export default "VIRTUAL:ONE"'

      else if (id === '/__virtual/2')
        return 'export default "VIRTUAL:TWO"'

      else
        throw new Error(`Unexpected id: ${id}`)
    },
  }
})

Additional context

No response

Logs

throw new Error(`Unexpected id: ${id}`)
              ^

Error: Unexpected id: \__virtual\1
    at Object.load (\unplugin\test\fixtures\virtual-module\unplugin.js:20:15)
    at Object.load (\unplugin\dist\rspack\loaders\load.js:115:33)
    at LOADER_EXECUTION (\unplugin\node_modules\.pnpm\@[email protected]_@[email protected]\node_modules\@rspack\core\dist\loader-runner\index.js:213:23)
    at runSyncOrAsync (\unplugin\node_modules\.pnpm\@[email protected]_@[email protected]\node_modules\@rspack\core\dist\loader-runner\index.js:214:11)
    at node:internal/util:441:7
    at new Promise (<anonymous>)
    at runSyncOrAsync (node:internal/util:427:12)
    at runLoaders (\unplugin\node_modules\.pnpm\@[email protected]_@[email protected]\node_modules\@rspack\core\dist\loader-runner\index.js:695:28)

Node.js v18.19.1
node:internal/errors:865
  const err = new Error(message);
              ^

Error: Command failed: npx rspack
    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at run (\unplugin\scripts\buildFixtures.ts:37:33) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 9396,
  stdout: null,
  stderr: null
}

Node.js v18.19.1
@tmg0 tmg0 added the bug Something isn't working label Sep 23, 2024
@tmg0
Copy link
Author

tmg0 commented Sep 25, 2024

I have created a demo for this issue, it works well on stackblitz and unix like platform:

/__virtual/1
/__virtual/2
asset main.js 5.11 KiB [compared for emit] (name: main)
runtime modules 670 bytes 3 modules
cacheable modules 139 bytes
  ./src/index.js 83 bytes [built] [code generated]
  ./_virtual_%2F__virtual%2F1 28 bytes [built] [code generated]
  ./_virtual_%2F__virtual%2F2 28 bytes [built] [code generated]
webpack 5.94.0 compiled successfully in 305 ms

But on windows, it was broken:

\__virtual\1
\__virtual\2
C:\webpack-webpack-js-org-fy87xb\plugin\virtual.js:20
        throw new Error(`Unexpected id: ${id}`)
              ^

Error: Unexpected id: \__virtual\1
    at Object.load (C:\webpack-webpack-js-org-fy87xb\plugin\virtual.js:20:15)
    at Object.load (C:\webpack-webpack-js-org-fy87xb\node_modules\.pnpm\u[email protected]\node_modules\unplugin-doctor\dist\index.cjs:5:524)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.load (C:\webpack-webpack-js-org-fy87xb\node_modules\.pnpm\u[email protected]\node_modules\unplugin\dist\webpack\loaders\load.js:130:15)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant