Skip to content

fix: resolve tailwindcss from file directory in monorepo setups#365

Open
hirbod wants to merge 1 commit intoschoero:mainfrom
hirbod:fix/monorepo-cwd-resolution
Open

fix: resolve tailwindcss from file directory in monorepo setups#365
hirbod wants to merge 1 commit intoschoero:mainfrom
hirbod:fix/monorepo-cwd-resolution

Conversation

@hirbod
Copy link
Copy Markdown

@hirbod hirbod commented Apr 16, 2026

Problem

In monorepos, IDE extensions (e.g. VS Code oxlint/eslint) run the linter from the repository root, while tailwindcss is installed in a workspace subdirectory. The plugin only looked for tailwindcss relative to ctx.cwd (the linter process directory), causing:

  1. resolveJson returned the raw input path on failure instead of undefined, bypassing the "not installed" guard and crashing with ENOENT: no such file or directory, open 'tailwindcss/package.json'
  2. Even with the cwd option from fix: remove auto detection of project root #364, no single relative path works for both IDE (repo root) and CLI (package directory) contexts

See #361 and this comment for the original report.

Fix

resolveJson: Return undefined on resolution failure instead of the input path. This ensures the if(!packageJsonPath) guard in createRule works correctly.

createRule: When tailwindcss is not found at the configured cwd, fall back to resolving from the directory of the file being linted. The enhanced-resolve walker finds tailwindcss by walking up the directory tree from the file, which always works regardless of where the linter process started. The resolved package location is then used to derive the correct cwd for downstream resolution (entryPoint, theme.css, etc.).

This makes most monorepo setups work without any cwd configuration.

Changes

  • src/async-utils/resolvers.tsresolveJson returns undefined on failure
  • src/utils/rule.ts — file-directory fallback when tailwindcss is not found at cwd
  • tests/unit/monorepo-resolution.test.ts — tests for monorepo root and workspace cwd scenarios
  • docs/settings/settings.md — improved cwd docs with monorepo explanation

When the linter process runs from a different directory than where
tailwindcss is installed (common with IDE extensions in monorepos),
the plugin now falls back to resolving from the file being linted
and walks up the directory tree.

Also fixes resolveJson to return undefined on failure instead of
the input path, which previously caused ENOENT errors instead of
the graceful "not installed" fallback.

Closes schoero#361
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.

1 participant