Skip to content

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

@tmg0

Description

@tmg0

Environment

  • platform: windows 10
  • nodejs: 18.19.1
  • package manager: pnpm@9.11.0

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\@rspack+core@1.0.0-rc.1_@swc+helpers@0.5.12\node_modules\@rspack\core\dist\loader-runner\index.js:213:23)
    at runSyncOrAsync (\unplugin\node_modules\.pnpm\@rspack+core@1.0.0-rc.1_@swc+helpers@0.5.12\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\@rspack+core@1.0.0-rc.1_@swc+helpers@0.5.12\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

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy