Skip to content

Resolve @imports that failed in a previous compile once the file exists - #20639

Open
lazerg wants to merge 5 commits into
tailwindlabs:mainfrom
lazerg:fix/issue-20638-resolver-cache
Open

lazerg wants to merge 5 commits into
tailwindlabs:mainfrom
lazerg:fix/issue-20638-resolver-cache

Conversation

@lazerg

@lazerg lazerg commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Summary

@tailwindcss/node creates its CSS and JS resolvers once at module load, each over a CachedInputFileSystem with a 4 second cache. In a long-lived process (a dev server, the PostCSS plugin in watch mode) a failed stat for an @import that doesn't exist yet stays cached, so recompiling right after the file is created still fails with Can't resolve until the entry expires.

The three resolvers now share one cached file system, and compile() / compileAst() purge it before they start. Lookups within a single compile are still cached, but each compile sees the current state of the disk.

Fixes #20638

Test plan

  • Added packages/@tailwindcss-node/src/compile.test.ts: compile an @import of a missing file (fails), write the file, compile again and expect it to resolve. It fails on main with Can't resolve './accent.css' and passes with this change.
  • pnpm build && pnpm vitest run: all unit tests pass.

@lazerg
lazerg requested a review from a team as a code owner November 1, 2026 01:13
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The CSS, ESM, and CJS resolvers now use a shared input file-system cache. The compile and compileAst functions purge that cache before compilation. New tests verify that both functions can resolve an import after its file is created following an initial resolution failure. They also verify that compilation fails again after the imported file is removed.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 6c16d

Imports that failed in an earlier compile now resolve on the next compile once the file exists, instead of failing for up to four seconds in long-lived processes. The change is small and tested, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: @imports that failed in a previous compile now resolve once the file exists. The changeset does this by sharing one cached file system across the three resolvers and…
Description check Passed The description states the problem: a cached failed stat for a missing @import keeps later compiles failing. It explains the fix: the three resolvers share one cached file system, which `compile()…
Linked Issues check Passed Issue #20638 requires that an @import which failed in an earlier compile resolves once its file exists, without waiting for the 4 s cache entry to expire. At head, compile() and compileAst() eac…
Out of Scope Changes check Passed The compile.ts changes serve the fix for #20638. They add the shared cache instance, the purge calls in compile and compileAst, and the resolver wiring that uses the shared instance. The compile.t…
Full details: Title check

Explanation

The title names the main change: @imports that failed in a previous compile now resolve once the file exists. The changeset does this by sharing one cached file system across the three resolvers and purging it at the start of compile() and compileAst(). The title is specific and matches the linked issue #20638.

Full details: Description check

Explanation

The description states the problem: a cached failed stat for a missing @import keeps later compiles failing. It explains the fix: the three resolvers share one cached file system, which compile() and compileAst() purge before they start. It also gives a test plan and links the issue, so it relates directly to the changeset.

Full details: Linked Issues check

Explanation

Issue #20638 requires that an @import which failed in an earlier compile resolves once its file exists, without waiting for the 4 s cache entry to expire. At head, compile() and compileAst() each call fileSystem.purge() before compiling. The CSS, ESM, and CJS resolvers all use the single shared CachedInputFileSystem instance fileSystem (compile.ts). The diff confirms this wiring. Lookups within one compile remain cached, and each compile starts from current disk state. The added tests in compile.test.ts cover the failing, create, and resolve sequence for both compile and compileAst. The changes since the previous review add a removal check and temporary-folder cleanup in the tests. They do not alter the fix path, so the earlier conclusion still holds. Residual uncertainty: the tests were not run in this review. The assessment relies on the source diff and the test summary.

Full details: Out of Scope Changes check

Explanation

The compile.ts changes serve the fix for #20638. They add the shared cache instance, the purge calls in compile and compileAst, and the resolver wiring that uses the shared instance. The compile.test.ts changes exercise this behavior. The test cleanup helper supports the same tests. The changelog entry in .changelog/resolve-import-after-file-exists.md documents the fix. No unrelated functional change appears in the reviewed diff.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 75b37e2d-2ebd-48b6-bacc-a5143877ce95
Commits

Reviewing files that changed from the base of the PR and between d3f9573 and 6c16d83.

Files selected for processing: 1

  • packages/@tailwindcss-node/src/compile.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (4) · Last reviewed commit: "Test that an `@import` fails again once ..." · Reviewed by Greptile

@RobinMalfait
RobinMalfait force-pushed the fix/issue-20638-resolver-cache branch from ae61ade to d3f9573 Compare November 16, 2026 21:46
@RobinMalfait

Copy link
Copy Markdown
Contributor

I rebased this PR on the latest main and force pushed it. The rebase had merge conflicts in CHANGELOG.md, and I resolved them.

Sent by an AI assistant on behalf of @RobinMalfait.

The tests removed their temporary folder only after all assertions
passed, so a failing test left it behind. Create and remove it in
`beforeEach` and `afterEach`, as the `@tailwindcss/postcss` tests do.
A stale cache can also keep a removed file resolved. Without the purge,
the next compile resolves the removed file and then fails with `ENOENT`
when it reads it, instead of `Can't resolve`.
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/node: an @import that failed to resolve keeps failing for up to 4 s after the file is written

2 participants