diff --git a/packages/vite/src/dev-bundler.ts b/packages/vite/src/dev-bundler.ts index fbc53ceb75..fc2e47a6ae 100644 --- a/packages/vite/src/dev-bundler.ts +++ b/packages/vite/src/dev-bundler.ts @@ -1,4 +1,6 @@ import { pathToFileURL } from 'url' +import { existsSync } from 'fs' +import { resolve } from 'pathe' import * as vite from 'vite' import { ExternalsOptions, isExternal as _isExternal, ExternalsDefaults } from 'externality' import { hashId, uniq } from './utils' @@ -61,7 +63,10 @@ async function transformRequest (opts: TransformOptions, id: string) { } } else if (!id.includes('entry') && id.startsWith('/')) { // Relative to the root directory - id = '.' + id + const resolvedPath = resolve(opts.viteServer.config.root, '.' + id) + if (existsSync(resolvedPath)) { + id = resolvedPath + } } if (await isExternal(opts, id)) {