Skip to content

Commit

Permalink
fix: address file path mismatch when loading Vite config file on Wind…
Browse files Browse the repository at this point in the history
…ows (fix #12923) (#13005)
  • Loading branch information
fwouts authored Apr 26, 2023
1 parent ad1ae3e commit 84c4118
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs'
import fsp from 'node:fs/promises'
import path from 'node:path'
import { pathToFileURL } from 'node:url'
import { promisify } from 'node:util'
import { performance } from 'node:perf_hooks'
import { createRequire } from 'node:module'
import colors from 'picocolors'
Expand Down Expand Up @@ -69,6 +70,7 @@ import type { ResolvedSSROptions, SSROptions } from './ssr'
import { resolveSSROptions } from './ssr'

const debug = createDebugger('vite:config')
const promisifiedRealpath = promisify(fs.realpath)

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

0 comments on commit 84c4118

Please sign in to comment.