Skip to content

8.3.8 (Windows): modules are bundled twice when the working directory has a lowercase drive letter #24145

Closed

Description

@nclemeur

Describe the bug

8.3.8 (Windows): modules are bundled twice when the working directory has a lowercase drive letter

Describe the bug

Since 8.3.8, on Windows, vite build started from a working directory spelled with a lowercase
drive letter (c:\project) bundles a module twice when it is imported both through a relative
path and through an alias built from import.meta.url (the '@' alias that create-vue scaffolds).
Each copy has its own module state, so singletons break at runtime: in our app the router was
duplicated and every page failed with "Router not installed". The build itself reports no error.

The same project builds a single copy with 8.3.7, and with 8.3.8 when the working directory is
spelled C:\project.

A lowercase drive letter is common: VS Code's integrated terminal starts in one, and so does a
process spawned from Node with such a cwd.

Cause, as far as I can tell

#24014 ("defer net use until a UNC path is resolved on Windows") changed what the first
safeRealpathSync calls return:

  • 8.3.7: windowsSafeRealPathSync returns fs.realpathSync(path), which keeps the drive letter as
    given (c:\project).
  • 8.3.8: windowsLazyRealpathSync returns fs.realpathSync.native(path) for any non-UNC path,
    which returns the canonical drive letter (C:\project).

resolveConfig passes the root through safeRealpathSync, so with 8.3.8 the root becomes
C:/project while process.cwd(), import.meta.url and import.meta.dirname in the config file
are still c:\project. /src/main.js from index.html then resolves to C:/project/src/main.js
and its relative imports stay under C:/, while @/state.js resolves to c:/project/src/state.js.
The two ids differ only by the case of the drive letter and are treated as two modules.

In 8.3.7 the root kept the case of the working directory, so both ids matched.

Reproduction

https://github.com/nclemeur/Vite-8.3.8-Issue

The files, for reference:

package.json

{
  "name": "vite-drive-letter-repro",
  "private": true,
  "type": "module",
  "devDependencies": { "vite": "8.3.8" }
}

index.html

<!doctype html>
<html>
  <body>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>

vite.config.js

import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'

export default defineConfig({
  resolve: {
    alias: {
      // as create-vue scaffolds it
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  build: { minify: false },
})

src/main.js

import { state as relative } from './state.js'
import { state as aliased } from '@/state.js'

// one module, imported twice: must be the same instance
console.log('same instance:', relative === aliased)

src/state.js

export const state = { marker: 'STATE_MODULE_MARKER' }

repro.mjs builds from the same directory spelled both ways and counts the copies of
src/state.js in the output:

import { spawnSync } from 'node:child_process'
import { readdirSync, readFileSync } from 'node:fs'
import { join } from 'node:path'

const dir = import.meta.dirname
for (const drive of [dir[0].toLowerCase(), dir[0].toUpperCase()]) {
  const cwd = drive + dir.slice(1)
  const r = spawnSync('npx vite build', { cwd, shell: true, stdio: 'ignore' })
  const assets = join(cwd, 'dist', 'assets')
  const copies = readdirSync(assets)
    .filter((f) => f.endsWith('.js'))
    .map((f) => readFileSync(join(assets, f), 'utf8').split('STATE_MODULE_MARKER').length - 1)
    .reduce((a, b) => a + b, 0)
  console.log(`cwd ${cwd.slice(0, 3)}...  exit ${r.status}  copies of src/state.js: ${copies}`)
}

Expected behaviour

One copy of src/state.js whatever the case of the drive letter, as in 8.3.7. Either the root
keeps the case of the working directory, or ids are compared with the drive letter normalised.

Used Package Manager

npm (also seen with Yarn 4, nodeLinker: node-modules)

Workaround

Stay on 8.3.7, or start the build from a directory spelled with an uppercase drive letter.

Reproduction

https://github.com/nclemeur/Vite-8.3.8-Issue

Steps to reproduce

Steps to reproduce

npm install
node repro.mjs

With vite 8.3.8:

cwd c:\...  exit 0  copies of src/state.js: 2
cwd C:\...  exit 0  copies of src/state.js: 1

With vite 8.3.7 (npm install -D -E vite@8.3.7):

cwd c:\...  exit 0  copies of src/state.js: 1
cwd C:\...  exit 0  copies of src/state.js: 1

The same can be seen by hand: open a terminal whose prompt shows c:\... (cd /d c:\path\to\repro
in cmd), run npx vite build, and search dist/assets/*.js for STATE_MODULE_MARKER.

System Info

### System Info


System:
  OS: Windows 11 Pro 10.0.26300
Binaries:
  Node: 24.12.0
npmPackages:
  vite: 8.3.8 (rolldown 1.2.19)


`net use` succeeds on this machine and lists one mapped drive; the project is on a local disk.

Used Package Manager

npm

Logs

No response

Validations

Activity

  1. added theissue type on Nov 19, 2026
  2. added
    p3-minor-bug
    regression
    and removed on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugregression

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions