Repository navigation
fix(css): never externalize css at-import specifiers (fix #23096) - #23099
ayaangazali wants to merge 1 commit into
Conversation
4b5c2b7 to
aee2e32
Compare
|
CI caught a real problem with my first push, so I've narrowed the fix. I had also passed So this now only touches the Re-ran locally on the amended commit: the previously failing |
|
Why did the repro work in v7? |
|
Good question, and the answer turned out to be about a missing opt-in rather than anything CSS specific. In v7, In v8, So the v7 behavior came from an opt-in that protected internal resolvers, and the native path does not have it. That raises a fair question about my patch: the more general fix would be to honour |
I think that's the same with v7. vite/packages/vite/src/node/plugins/resolve.ts Lines 205 to 210 in 0a7b53b |
fixes #23096
A CSS
@import "somepkg"that resolves through the package'sstyleexport condition works in a client build but dies in a server build withENOENT ... open '<projectRoot>/somepkg'. The at-import resolvers increateCSSResolvers(packages/vite/src/node/plugins/css.ts:1361) are built withcreateBackCompatIdResolver, so in a server environment the bare specifier gets externalized and comes back unchanged. The postcss-importresolvecallback at css.ts:1637 only checks that the value is truthy, so it takes the success branch andpath.resolves the bare specifier against the root. That is also why theUnable to resolve \@import`` message never appears, which made the ENOENT point at a path nobody wrote.These three resolvers only exist to turn a specifier into a file we then read off disk, so externalization has no meaning for them, and
noExternal: trueis what the resolve options already offer for exactly that. I applied it to the sass and less resolvers too since they are built the same way and hit the same path. The alternative I tried first was rejecting non-absolute results in the postcss-import callback, but that only turns the confusing ENOENT into a clearer error and leaves the import unresolved, so the build still fails where a client build succeeds.Worth noting the existing
csstest inenvironment.spec.tsonly passed because it setsresolve.noExternal: truein the user config, which is the workaround this bug forces on people. The new test builds the same fixture with externalization left at its default and fails on main with the ENOENT above. Gates run locally:pnpm build,pnpm lint,pnpm typecheck, the css/environment unit specs, plustest-serveandtest-buildfor the css, ssr and tailwind playgrounds.quick note on process: I'm a college freshman and still pretty new to this codebase, so apologies in advance if I've missed something obvious. I worked through the root cause and the fix with Claude Code (we traced the resolver path together, I reproduced it in a standalone project first, and I ran the gates above locally). Happy to change the approach if you'd rather see the guard live in the postcss-import callback, and genuinely glad to learn from anything I got wrong here.