@@ -2,7 +2,7 @@ import EnhancedResolve from 'enhanced-resolve'
2
2
import { createJiti , type Jiti } from 'jiti'
3
3
import fs from 'node:fs'
4
4
import fsPromises from 'node:fs/promises'
5
- import path , { dirname } from 'node:path'
5
+ import path , { dirname , extname } from 'node:path'
6
6
import { pathToFileURL } from 'node:url'
7
7
import { compile as _compile } from 'tailwindcss'
8
8
import { getModuleDependencies } from './get-module-dependencies'
@@ -100,13 +100,22 @@ async function resolveCssId(id: string, base: string): Promise<string | false |
100
100
}
101
101
}
102
102
103
- try {
104
- let dotResolved = await runResolver ( cssResolver , `./${ id } ` , base )
105
- if ( ! dotResolved ) throw new Error ( )
106
- return dotResolved
107
- } catch {
108
- return runResolver ( cssResolver , id , base )
103
+ // CSS imports that do not have a dir prefix are considered relative. Since
104
+ // the resolver does not account for this, we need to do a first pass with an
105
+ // assumed relative import by prefixing `./${path}`. We don't have to do this
106
+ // when the path starts with a `.` or when the path has no extension (at which
107
+ // case it's likely an npm package and not a relative stylesheet).
108
+ let skipRelativeCheck = extname ( id ) === '' || id . startsWith ( '.' )
109
+
110
+ if ( ! skipRelativeCheck ) {
111
+ try {
112
+ let dotResolved = await runResolver ( cssResolver , `./${ id } ` , base )
113
+ if ( ! dotResolved ) throw new Error ( )
114
+ return dotResolved
115
+ } catch { }
109
116
}
117
+
118
+ return runResolver ( cssResolver , id , base )
110
119
}
111
120
112
121
const jsResolver = EnhancedResolve . ResolverFactory . createResolver ( {
0 commit comments