Skip to content

Fix issue around resolving paths in @tailwindcss/vite#19947

Merged
RobinMalfait merged 4 commits intomainfrom
fix/issue-19946
Apr 21, 2026
Merged

Fix issue around resolving paths in @tailwindcss/vite#19947
RobinMalfait merged 4 commits intomainfrom
fix/issue-19946

Conversation

@RobinMalfait
Copy link
Copy Markdown
Member

@RobinMalfait RobinMalfait commented Apr 21, 2026

This PR fixes an issue when using @tailwindcss/vite and you're trying to resolve paths. In the latest 4.2.3 release, we added support for following the vite aliases option.

However, some people run into issues because if you just use @ as an alias then using @tailwindcss/typography wouldn't resolve because it's a package, and not something local.

With this PR we fix that by making sure that Vite's resolver can actually resolve to an absolute path. If not, then we fallback to the resolving that happens in @tailwindcss/node.

Fixes: #19946

Test plan

  1. Added an integration test that reproduces this issue, and is now solved
  2. Tested it on a reproduction provided in the corresponding issue

Before:
image

After:
image

This adds some guards to make sure that if we resolve a value, that:

1. It actually resolved _something_
2. It's not the same as the `id` we provided
3. It's an absolute path (which we can read from disk)

If that's not the case, then we end up with `undefined`, which means
that the `@tailwindcss/node` resolver will kick in and try to resolve
that way.

This should make it compatible with Vite projects that have an `@` alias
setup.
@RobinMalfait RobinMalfait requested a review from a team as a code owner April 21, 2026 12:01
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b26f7bd2-932a-4ff7-80ee-b046057dcdc9

📥 Commits

Reviewing files that changed from the base of the PR and between 0403d61 and 87961c4.

📒 Files selected for processing (1)
  • CHANGELOG.md

Walkthrough

Adds Vite and SvelteKit integration tests to validate Tailwind CSS alias resolution and plugin package loading: two tests in integrations/vite/resolvers.test.ts for @-prefixed imports and one test in integrations/vite/sveltekit.test.ts for SvelteKit builds. Refactors Vite integration resolver hooks in packages/@tailwindcss-vite/src/index.ts to async resolvers with explicit guards. Removes a trailing blank line from packages/@tailwindcss-postcss/README.md and adds a note to CHANGELOG.md.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing path resolution issues in @tailwindcss/vite when using Vite aliases.
Description check ✅ Passed The description clearly explains the issue, the solution, and includes test plan with before/after examples demonstrating the fix.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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


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.

Actionable comments posted: 1

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

167-289: Add a Vite 5 regression test for package plugins with at-sign aliases.

The new package-plugin regressions only test vite: "^8". However, packages/@tailwindcss-vite/src/index.ts contains a separate back-compat resolver path for older Vite APIs (lines 51-53: "Older, pre-environment Vite API"; lines 93-119: createBackCompatIdResolver with comment "Remove this function and pre-environment code when Vite < 7 is no longer supported"). Adding a Vite 5-style regression combining package plugins and @-aliases would prevent that compatibility branch from drifting.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@integrations/vite/resolvers.test.ts` around lines 167 - 289, Add a Vite 5
regression test variant that exercises the back-compat resolver path by
duplicating the "resolves package plugins in production build with at-sign
aliases" test but using "vite": "^5" in its devDependencies (so the test hits
the older pre-environment API and createBackCompatIdResolver code path in
packages/@tailwindcss-vite/src/index.ts); keep the same fixtures (index.html,
src/index.css with `@plugin` entries, and vite.config.ts that defines the "@"
alias) and the same assertions against the built CSS to ensure package plugins +
`@-aliases` work under Vite 5.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@integrations/vite/sveltekit.test.ts`:
- Around line 75-78: The test currently assumes the first matched CSS asset
contains the class by using files[0][0]; change the assertion to scan all
results from fs.glob (the files variable) and assert that at least one of the
matched file paths passed to fs.expectFileToContain contains the
candidate`form-input` token. In other words, iterate over files (from fs.glob),
call or check each path with fs.expectFileToContain (or read and check contents)
and assert that some file includes candidate`form-input`, rather than relying on
files[0][0].

---

Nitpick comments:
In `@integrations/vite/resolvers.test.ts`:
- Around line 167-289: Add a Vite 5 regression test variant that exercises the
back-compat resolver path by duplicating the "resolves package plugins in
production build with at-sign aliases" test but using "vite": "^5" in its
devDependencies (so the test hits the older pre-environment API and
createBackCompatIdResolver code path in
packages/@tailwindcss-vite/src/index.ts); keep the same fixtures (index.html,
src/index.css with `@plugin` entries, and vite.config.ts that defines the "@"
alias) and the same assertions against the built CSS to ensure package plugins +
`@-aliases` work under Vite 5.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 43e57313-71c8-435a-bf7c-683867e18b4e

📥 Commits

Reviewing files that changed from the base of the PR and between 2e3fa49 and 0403d61.

📒 Files selected for processing (4)
  • integrations/vite/resolvers.test.ts
  • integrations/vite/sveltekit.test.ts
  • packages/@tailwindcss-postcss/README.md
  • packages/@tailwindcss-vite/src/index.ts
💤 Files with no reviewable changes (1)
  • packages/@tailwindcss-postcss/README.md

Comment on lines +75 to +78
let files = await fs.glob('.svelte-kit/output/client/**/*.css')
expect(files.length).toBeGreaterThan(0)

await fs.expectFileToContain(files[0][0], [candidate`form-input`])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Don't rely on the first emitted CSS asset.

SvelteKit can emit multiple client CSS files, and files[0][0] makes this regression depend on glob ordering. Scan all matched CSS assets and assert that at least one contains candidate\form-input`` instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@integrations/vite/sveltekit.test.ts` around lines 75 - 78, The test currently
assumes the first matched CSS asset contains the class by using files[0][0];
change the assertion to scan all results from fs.glob (the files variable) and
assert that at least one of the matched file paths passed to
fs.expectFileToContain contains the candidate`form-input` token. In other words,
iterate over files (from fs.glob), call or check each path with
fs.expectFileToContain (or read and check contents) and assert that some file
includes candidate`form-input`, rather than relying on files[0][0].

@RobinMalfait RobinMalfait merged commit 685c19e into main Apr 21, 2026
@RobinMalfait RobinMalfait deleted the fix/issue-19946 branch April 21, 2026 12:11
loimabean added a commit to loimabean/loim-dev-svelte that referenced this pull request Apr 21, 2026
tailwind fixed the bug using this website as their test project!
tailwindlabs/tailwindcss#19947

so now we can update to the latest tailwind. also, minor stylistic
change in the Containerfile as this article says to run using `node
build` https://svelte.dev/docs/kit/adapter-node#Deploying

pretty sure it's basically the exact same thing but let's use their
version :)
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.

@tailwindcss/vite: build error when use @plugin "@tailwindcss/typography";

1 participant