Skip to content

Fix Vite resolution for bare CSS imports#20056

Open
yudin-s wants to merge 2 commits into
tailwindlabs:mainfrom
yudin-s:fix-vite-bare-css-imports
Open

Fix Vite resolution for bare CSS imports#20056
yudin-s wants to merge 2 commits into
tailwindlabs:mainfrom
yudin-s:fix-vite-bare-css-imports

Conversation

@yudin-s
Copy link
Copy Markdown
Contributor

@yudin-s yudin-s commented May 14, 2026

Summary

Fixes #19719.

When Vite's CSS resolver treats a same-folder import like @import "components.css" as a package import, Tailwind currently reports that the file cannot be resolved. This keeps the existing Vite resolver flow first, then adds a narrow fallback for bare .css filenames that exist next to the importing stylesheet.

Test plan

  • pnpm build
  • pnpm run test:integrations vite/resolvers.test.ts -t "resolve bare CSS imports in the same folder"
  • git diff --check
  • pnpm exec prettier --check packages/@tailwindcss-vite/src/index.ts

@yudin-s yudin-s requested a review from a team as a code owner May 14, 2026 15:27
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 14, 2026

Confidence Score: 5/5

Safe to merge — the fallback is strictly additive, only fires after all Vite resolvers have already failed, and is guarded by multiple narrow conditions that prevent it from intercepting legitimate package imports.

The fallback logic is well-constrained: it requires a bare filename with no path separators, no leading dot, a non-absolute path, a passing filter, and actual filesystem presence — all of which must be true before the fallback activates. The existing resolver chain is completely unchanged; this only runs when every upstream resolver returns nothing. Both build and dev-mode integration tests are included and mirror the pattern used throughout the file.

No files require special attention.

Reviews (2): Last reviewed commit: "test(vite): cover bare css imports in de..." | Re-trigger Greptile

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

Review Change Stack

Walkthrough

Adds a fallback in packages/@tailwindcss-vite/src/index.ts so createCustomResolver resolves non-relative, non-absolute CSS imports like "components.css" by checking path.resolve(base, id) and returning it when the file exists. Adds two Vitest integration tests in integrations/vite/resolvers.test.ts: one verifies the behavior during a production build by snapshotting emitted CSS, the other verifies the behavior in dev mode by fetching the compiled stylesheet and asserting the expected rules and declarations.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix Vite resolution for bare CSS imports' accurately describes the main change: adding resolution support for bare CSS imports without './' prefix in Vite.
Linked Issues check ✅ Passed The PR successfully addresses issue #19719 by implementing bare CSS import resolution in the Vite plugin and adding comprehensive integration tests covering both dev and production modes.
Out of Scope Changes check ✅ Passed All changes are scoped to the Vite resolver: integration test coverage and a narrow CSS import fallback in the custom resolver function.
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the issue being fixed (#19719), the solution approach, and providing a test plan.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
integrations/vite/resolvers.test.ts (1)

587-647: ⚡ Quick win

Add a dev-mode companion test for this regression.

This case reproduces in build, but the reported failure path is @tailwindcss/vite:generate:serve. Please add a pnpm vite dev variant of the same fixture/assertion to lock coverage on the serve resolver path too.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integrations/vite/resolvers.test.ts` around lines 587 - 647, Duplicate the
existing "resolve bare CSS imports in the same folder" test as a dev-mode
variant that runs the dev server instead of build: use the same fs fixture and
vite.config.ts, call exec('pnpm vite dev') (or appropriate command the test
harness uses for starting dev) and wait for the dev server to finish startup;
then assert the served/generated CSS matches the same expected content (the
.component-style CSS) to exercise the `@tailwindcss/vite`:generate:serve code
path. Ensure the new test name indicates it's a dev-mode variant and reuse the
same assertions/normalization (e.g. replacing hashed names) so coverage hits the
serve resolver path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@integrations/vite/resolvers.test.ts`:
- Around line 587-647: Duplicate the existing "resolve bare CSS imports in the
same folder" test as a dev-mode variant that runs the dev server instead of
build: use the same fs fixture and vite.config.ts, call exec('pnpm vite dev')
(or appropriate command the test harness uses for starting dev) and wait for the
dev server to finish startup; then assert the served/generated CSS matches the
same expected content (the .component-style CSS) to exercise the
`@tailwindcss/vite`:generate:serve code path. Ensure the new test name indicates
it's a dev-mode variant and reuse the same assertions/normalization (e.g.
replacing hashed names) so coverage hits the serve resolver path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 609e9053-645e-4573-934b-99afc06dc96c

📥 Commits

Reviewing files that changed from the base of the PR and between 460a008 and 63aa150.

📒 Files selected for processing (2)
  • integrations/vite/resolvers.test.ts
  • packages/@tailwindcss-vite/src/index.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin:@tailwindcss/vite fails to resolve css file import in same folder if not prefixed with ./

1 participant