File tree 1 file changed +11
-1
lines changed
packages/vite/src/node/plugins 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,16 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
127
127
128
128
const { target : ssrTarget , noExternal : ssrNoExternal } = ssrConfig ?? { }
129
129
130
+ // In unix systems, absolute paths inside root first needs to be checked as an
131
+ // absolute URL (/root/root/path-to-file) resulting in failed checks before falling
132
+ // back to checking the path as absolute. If /root/root isn't a valid path, we can
133
+ // avoid these checks. Absolute paths inside root are common in user code as many
134
+ // paths are resolved by the user. For example for an alias.
135
+ const rootInRoot =
136
+ fs
137
+ . statSync ( path . join ( root , root ) , { throwIfNoEntry : false } )
138
+ ?. isDirectory ( ) ?? false
139
+
130
140
return {
131
141
name : 'vite:resolve' ,
132
142
@@ -256,7 +266,7 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
256
266
257
267
// URL
258
268
// /foo -> /fs-root/foo
259
- if ( asSrc && id . startsWith ( '/' ) ) {
269
+ if ( asSrc && id . startsWith ( '/' ) && ( rootInRoot || ! id . startsWith ( root ) ) ) {
260
270
const fsPath = path . resolve ( root , id . slice ( 1 ) )
261
271
if ( ( res = tryFsResolve ( fsPath , options ) ) ) {
262
272
isDebug && debug ( `[url] ${ colors . cyan ( id ) } -> ${ colors . dim ( res ) } ` )
You can’t perform that action at this time.
0 commit comments