fix(vite): resolve tsconfig paths in CSS and JS resolvers#19803
fix(vite): resolve tsconfig paths in CSS and JS resolvers#19803RobinMalfait merged 4 commits intotailwindlabs:mainfrom
Conversation
Change `aliasOnly` from `true` to `false` when calling Vite's resolver so that the full resolution pipeline runs, including the oxc resolver responsible for tsconfig path resolution. When `aliasOnly` was `true`, only the @rollup/plugin-alias plugin ran, which meant `resolve.tsconfigPaths: true` had no effect on CSS `@import` or JS `@plugin` resolution in `@tailwindcss/vite`. Closes tailwindlabs#19802
|
Caution Review failedPull request was closed or merged during review WalkthroughThe PR adds an import for 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
integrations/vite/resolvers.test.ts (1)
15-165: Optional: extract shared fixture setup to reduce duplication.Both new tests repeat the same filesystem fixture; extracting a small helper/object for shared files would make future resolver test updates less error-prone.
🤖 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 15 - 165, Extract the duplicated filesystem fixture used in the two tests titled "resolves tsconfig paths in production build" and "resolves tsconfig paths in dev mode" into a shared constant (e.g., sharedFs) and reference that constant in each test's options instead of duplicating the object; update the tests to pass the sharedFs to the test helper (replace the inline fs: { ... } blocks with fs: sharedFs) so future changes to the fixture live in one place and both tests (production build and dev mode) reuse the same setup.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@integrations/vite/resolvers.test.ts`:
- Around line 15-165: Extract the duplicated filesystem fixture used in the two
tests titled "resolves tsconfig paths in production build" and "resolves
tsconfig paths in dev mode" into a shared constant (e.g., sharedFs) and
reference that constant in each test's options instead of duplicating the
object; update the tests to pass the sharedFs to the test helper (replace the
inline fs: { ... } blocks with fs: sharedFs) so future changes to the fixture
live in one place and both tests (production build and dev mode) reuse the same
setup.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a1c6b6ce-a66b-41d5-a9dd-78be04245a20
📒 Files selected for processing (2)
integrations/vite/resolvers.test.tspackages/@tailwindcss-vite/src/index.ts
|
Hey! Looks like CI is failing. Do you mind making sure that things work as expected? Thanks! |
|
Thanks for the ping @RobinMalfait. I believe this is now fixed. When That said, I'm unsure whether the remaining test failures are related to my change or an environmental issue.
|
RobinMalfait
left a comment
There was a problem hiding this comment.
Running all the integration tests locally can result in issues when ports are already occupied. In CI, we split them so that doesn't happen. What I typically do locally is only run a single integration test at a time (typically the one I'm working on).
Since they pass in CI, I wouldn't worry about them locally 👍
Thanks for the contribution!
Edit: some edits by @RobinMalfait --- ## Summary Fix a regression in `@tailwindcss/vite` introduced by `#19803` where JS plugin resolution could incorrectly resolve a package to its `browser` CSS entry. In cases like `daisyui`, Vite can resolve `@plugin "daisyui"` to `daisyui.css` instead of the package's JS entry, which causes Tailwind to try to load a CSS file as a JS plugin and fail with: ```txt Unknown file extension ".css" ``` This change keeps the `aliasOnly: false` behavior from `#19803` so tsconfig path resolution still works, but adds a JS-entry guard to `customJsResolver` in `@tailwindcss/vite`. If Vite resolves a plugin request to a non-JS file like `.css`, the custom resolver now returns `undefined` so Tailwind's internal fallback resolver can resolve the package as a JS plugin entry instead. I also added integration coverage for a package whose `main`/`module` points to JS while `browser` points to CSS, and verified that `@plugin "pkg"` still resolves to the JS entry in both build and dev mode. ## Test plan Added new integration tests in `integrations/vite/resolvers.test.ts` covering a package with: - `main` / `module` -> JS - `browser` -> CSS - `@plugin "pkg"` -> should resolve to JS, not CSS Verified with: ```sh pnpm test:integrations vite/resolvers.test.ts -t "browser points to CSS" pnpm test:integrations vite/resolvers.test.ts -t "resolves tsconfig paths" ``` These verify that: - `@plugin` no longer resolves to a CSS browser entry - the original tsconfig paths fix from `#19803` still works in both build and dev mode --- Maintainer edits: Instead of hardcoding file extensions, first try to resolve aliases and then fallback to the default resolving system we had before. We still check for a `.css` extension, even in the JS resolver because some dependencies (like `daisyUI`) put the CSS file there instead of in an `exports.style`. If we detect that, we still fallback to the default resolving logic. This should be compatible with the original issue we were trying to fix where we wanted to make Vite aliases work. Fixes: #19950 [ci-all] --------- Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
Change
aliasOnlyfromtruetofalsewhen calling Vite's resolver so that the full resolution pipeline runs, including the oxc resolver responsible for tsconfig path resolution.When
aliasOnlywastrue, only the @rollup/plugin-alias plugin ran, which meantresolve.tsconfigPaths: truehad no effect on CSS@importor JS@pluginresolution in@tailwindcss/vite.Closes #19802.