Skip to content

CSS @import of a bare package specifier resolves in client builds but fails in SSR builds #23096

Closed

Description

@afuno

Describe the bug

A CSS file containing @import "tailwindcss"; builds fine in a client build and fails in an SSR
build. Same project, same files, same Vite — the only difference is the --ssr flag:

$ npx vite build                          ✓ built in 2.14s
$ npx vite build --ssr entry-server.js    ✗ [postcss] ENOENT: no such file or directory,
                                            open '<projectRoot>/tailwindcss'

The path in the error appears in no source file: it is the bare specifier resolved against the
project root.

**Vite's own Unable to resolve \@import "…"`message is never emitted** — zero occurrences in the full--debug` output. So the only symptom is an ENOENT naming a path nobody wrote, which points at
nothing.

Changing the import to @import "tailwindcss/index.css"; makes the SSR build succeed.

Not submitting a PR.

The resolver appears to report success on failure

dist/node/chunks/node.js (8.1.5):

  1. :22574 — const needInlineImport = code.includes("@import");
  2. :22580 — if (needInlineImport) postcssPlugins.unshift(…) — the bundled postcss-import goes to
    position 0, ahead of any user PostCSS plugin.
  3. :22584-22587 —
    const resolved = await atImportResolvers.css(environment, id, atRule.source?.input.file);
    if (resolved) return path.resolve(resolved);
    if (!path.isAbsolute(id)) environment.logger.error(`Unable to resolve \`@import "${id}"\` …`);
    return id;
  4. ENOENT on the resulting <projectRoot>/tailwindcss.

The error being logged zero times, together with an ENOENT naming <projectRoot>/tailwindcss,
seems jointly consistent only with atImportResolvers.css returning a truthy unresolved value — the
bare string itself — so the truthy branch is taken and the error branch is skipped. A falsy return
would have produced the clear message instead.

The bare specifier is expected to resolve

The CSS resolver is configured for this case at :22453-22465 — extensions: [".css"],
mainFields: ["style"], conditions: ["style", …], tryIndex: false — and tailwindcss@4.3.3
declares "style": "index.css" and exports["."].style = "./index.css", with
node_modules/tailwindcss/index.css present.

Both explicit subpaths work, which localises it

@import "tailwindcss/index.css";   /* SSR build succeeds */
@import "tailwindcss/index";       /* SSR build succeeds */

The extensionless form matters because tryIndex: false — it is not succeeding by index-guessing;
./index is an explicit key in the exports map. Both working forms name a literal key and need no
condition matching, while the failing bare form requires resolving exports["."] through the style
condition. So the failure looks specific to conditional resolution of the package root, in the
SSR environment only.

Relationship to #22766 / #22775 — same call site, opposite branch, and the fix is already in

#22766 ("Vite 8.1 doesn't resolve tsconfigPaths in CSS @import directives") is the nearest
existing report and is not this bug. Its own log shows three differences:

#22766 this report
Unable to resolve … present absent, 0 matches under --debug
ENOENT path open '@/styles/imported.css' — the raw specifier open '<root>/tailwindcss' — path.resolve applied
Environment building client environment SSR only; the client build of the same project succeeds

Those are the two branches of the same four lines. In #22766 the resolver returned falsy, so the
error branch ran, the message was logged, and return id handed postcss-import the raw specifier —
which is why their ENOENT names it unchanged. Here the resolver returns truthy, so
path.resolve(resolved) runs on an unresolved bare string and no message is logged — which is why
the ENOENT names a root-joined path instead. Their log shows what the falsy path looks like, and it
looks nothing like this.

The fix for #22766 shipped and does not cover this. #22775 ("fix(css): resolve tsconfig paths
in CSS and Sass @import") merged 2026-06-30 and changed the importer passed to the resolver. That
change is present in the 8.1.5 build used here — :22584 reads
atImportResolvers.css(environment, id, atRule.source?.input.file), the fixed form. 8.1.5 was
published 2026-07-16.

So this is not a case the importer fix missed by timing; it is an adjacent failure mode at the same
call site that the fix does not address, because it turns on conditional resolution of a package root
rather than on tsconfig ownership of the importer.

#22837 and #23052 are also open against CSS @import resolution after the 8.1 change, and are
likewise distinct from this case.

Version boundary

Vite 7.3.3 builds the same project. 8.1.5 fails. The failure path is unchanged in 8.2.0-beta.0 —
needInlineImport at :23055, the unshift at :23061, the identical resolve callback at
:23065-23068, and createCSSResolvers with the same options at :22934-22943; only line numbers
shift.

Vite 8.1 moved CSS resolution to oxc-resolver, which is a plausible origin. oxc-resolver ships
inside rolldown, and I did not diff rolldown
— so this identifies where the failure surfaces in
Vite's call path, not its final home.

Scope

Tested with tailwindcss only. The mechanism is not obviously specific to it — it turns on resolving
a package root through an exports condition — but I have not verified another package, so Tailwind
should be read as the example I measured rather than as the boundary of the bug.

Also reproduces through Nuxt 4.5.1, where the client environment builds and emits CSS and the SSR
environment fails identically. That is what led here; the reproduction below removes the framework
entirely.

Workaround

@import "tailwindcss/index.css"; — output verified equivalent to the Vite 7 build.

Reproduction

https://codesandbox.io/p/sandbox/wnh9c8

Steps to reproduce

Six files, no framework.

package.json

{
  "name": "vite-ssr-css-bare-import",
  "private": true,
  "type": "module",
  "dependencies": {
    "@tailwindcss/postcss": "^4.3.3",
    "tailwindcss": "^4.3.3",
    "vite": "^8.1.5"
  }
}

postcss.config.js

export default { plugins: { '@tailwindcss/postcss': {} } }

src/style.css

@import "tailwindcss";

index.html — the client entry

<!doctype html>
<html>
  <body>
    <script type="module" src="/main.js"></script>
  </body>
</html>

main.js — client entry module

import './src/style.css'

entry-server.js — SSR entry module

import './src/style.css'
export function render() { return '<div>hi</div>' }

Both entries import the same stylesheet; only the build mode differs.

npm install

npx vite build
# ✓ built in 464ms
# dist/assets/index-B2VE6WIS.css   4.19 kB │ gzip: 1.40 kB   ← Tailwind resolved and emitted

npx vite build --ssr entry-server.js
# ✗ Error: [postcss] ENOENT: no such file or directory, open '<projectRoot>/tailwindcss'

The client build emitting 4.19 kB of CSS is the point: the stylesheet is not merely skipped there,
it is processed and Tailwind resolves. Only the SSR build fails.

Changing src/style.css to @import "tailwindcss/index.css"; makes the SSR build succeed.

System Info

System:
    OS: macOS 26.5.2
    CPU: (11) arm64 Apple M3 Pro
    Memory: 210.63 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.18.0 - /opt/homebrew/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 11.16.0 - /opt/homebrew/bin/npm
    pnpm: 10.22.0 - /opt/homebrew/bin/pnpm
    bun: 1.3.14 - /Users/profox/.bun/bin/bun
  Browsers:
    Chrome: 150.0.7871.187
    Safari: 26.5.2
  npmPackages:
    vite: ^8.1.5 => 8.1.5

Used Package Manager

npm

Logs

Click to expand!
$ npx vite build --ssr entry-server.js --debug

error during build:
Build failed with 1 error:

[plugin vite:css] /private/tmp/vite-ssr-repro/src/style.css:undefined:NaN
Error: [postcss] ENOENT: no such file or directory, open '/private/tmp/vite-ssr-repro/tailwindcss'
    at async open (node:internal/fs/promises:640:25)
    at async Object.readFile (node:internal/fs/promises:1290:14)
    at async Object.load (vite/dist/node/chunks/node.js:22590:17)
    at async loadImportContent (vite/dist/node/chunks/postcss-import.js:392:19)
    at async Promise.all (index 0)
    at async resolveImportId (vite/dist/node/chunks/postcss-import.js:378:20)
    at async parseStyles (vite/dist/node/chunks/postcss-import.js:331:4)
    at async Object.Once (vite/dist/node/chunks/postcss-import.js:455:20)
    at async LazyResult.runAsync (postcss/lib/lazy-result.js:299:11)
    at async runPostCSS (vite/dist/node/chunks/node.js:22644:19)
    at aggregateBindingErrorsIntoJsError (rolldown/dist/shared/error-BHRSI0R7.mjs:48:18)
    at unwrapBindingResult (rolldown/dist/shared/error-BHRSI0R7.mjs:18:128)
    at #build (rolldown/dist/shared/rolldown-build-CtPvmZgJ.mjs:3276:34)
    at async buildEnvironment (vite/dist/node/chunks/node.js:33061:66)
    at async Object.build (vite/dist/node/chunks/node.js:33483:19)

# grepping the full 1415-line --debug output for "Unable to resolve" returns 0 matches

Validations

Activity

  1. added theissue type on Jul 28, 2026
  2. added
    p3-minor-bug
    and removed on Jul 29, 2026
  3. added a commit that references this issue on Jul 29, 2026
  4. CaliLuke commented on Oct 23, 2026

    @CaliLuke

    Confirmed with Vite 8.3.5, Tailwind CSS 4.3.3, and @tailwindcss/postcss 4.3.3 on Node 26.12.0 / pnpm 11.3.0 (macOS arm64).

    I recreated the six-file, framework-free example above with exact dependency versions:

    • Client build with @import "tailwindcss": succeeds and emits CSS.
    • SSR build with the same import: fails with ENOENT for <projectRoot>/tailwindcss.
    • Changing only the stylesheet import to @import "tailwindcss/index.css": SSR build succeeds.

    The failure therefore still reproduces in 8.3.5, and the explicit exported CSS subpath still avoids it. The expected behavior is for both build environments to resolve the package's style export consistently.

  5. added a commit that references this issue on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: cssfeat: ssrp3-minor-bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions