Skip to content

Commit 84c4118

Browse files
authoredApr 26, 2023
fix: address file path mismatch when loading Vite config file on Windows (fix #12923) (#13005)
1 parent ad1ae3e commit 84c4118

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed
 

‎packages/vite/src/node/config.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'node:fs'
22
import fsp from 'node:fs/promises'
33
import path from 'node:path'
44
import { pathToFileURL } from 'node:url'
5+
import { promisify } from 'node:util'
56
import { performance } from 'node:perf_hooks'
67
import { createRequire } from 'node:module'
78
import colors from 'picocolors'
@@ -69,6 +70,7 @@ import type { ResolvedSSROptions, SSROptions } from './ssr'
6970
import { resolveSSROptions } from './ssr'
7071

7172
const debug = createDebugger('vite:config')
73+
const promisifiedRealpath = promisify(fs.realpath)
7274

7375
export type {
7476
RenderBuiltAssetUrl,
@@ -1106,7 +1108,11 @@ async function loadConfigFromBundledFile(
11061108
// for cjs, we can register a custom loader via `_require.extensions`
11071109
else {
11081110
const extension = path.extname(fileName)
1109-
const realFileName = await fsp.realpath(fileName)
1111+
// We don't use fsp.realpath() here because it has the same behaviour as
1112+
// fs.realpath.native. On some Windows systems, it returns uppercase volume
1113+
// letters (e.g. "C:\") while the Node.js loader uses lowercase volume letters.
1114+
// See https://github.com/vitejs/vite/issues/12923
1115+
const realFileName = await promisifiedRealpath(fileName)
11101116
const loaderExt = extension in _require.extensions ? extension : '.js'
11111117
const defaultLoader = _require.extensions[loaderExt]!
11121118
_require.extensions[loaderExt] = (module: NodeModule, filename: string) => {

0 commit comments

Comments
 (0)
Please sign in to comment.