Skip to content

fix: resolve tailwindcss from project context in monorepo setups - #1771

Open
elizhabiboullah wants to merge 1 commit into
nativewind:v4from
elizhabiboullah:fix/monorepo-tailwind-resolution-v4
Open

elizhabiboullah wants to merge 1 commit into
nativewind:v4from
elizhabiboullah:fix/monorepo-tailwind-resolution-v4

Conversation

@elizhabiboullah

Copy link
Copy Markdown

In pnpm monorepos, NativeWind's own node_modules may contain a nested copy of tailwindcss (potentially v4) which differs from the version installed in the user's project. This causes three distinct failures:

  1. Version check fails: The import of tailwindcss/package.json resolves from NativeWind's node_modules, detecting v4 and throwing 'NativeWind only supports Tailwind CSS v3' even when the project has v3 correctly installed.

  2. loadConfig export missing: require('tailwindcss/loadConfig') resolves to the nested v4 copy which does not export this subpath, causing ERR_PACKAGE_PATH_NOT_EXPORTED errors.

  3. Config path resolution: The default tailwind.config path is resolved relative to cwd, which in monorepo setups (where you run from the workspace root) points to the wrong directory.

This commit fixes all three issues:

  • Uses require.resolve with paths:[process.cwd()] to resolve tailwindcss from the user's project context first, falling back to NativeWind's own resolution.
  • Resolves configPath relative to projectRoot when provided.
  • Improves error messages with actionable guidance for monorepo users.

In pnpm monorepos, NativeWind's own node_modules may contain a nested
copy of tailwindcss (potentially v4) which differs from the version
installed in the user's project. This causes three distinct failures:

1. Version check fails: The import of tailwindcss/package.json resolves
   from NativeWind's node_modules, detecting v4 and throwing
   'NativeWind only supports Tailwind CSS v3' even when the project
   has v3 correctly installed.

2. loadConfig export missing: require('tailwindcss/loadConfig') resolves
   to the nested v4 copy which does not export this subpath, causing
   ERR_PACKAGE_PATH_NOT_EXPORTED errors.

3. Config path resolution: The default tailwind.config path is resolved
   relative to cwd, which in monorepo setups (where you run from the
   workspace root) points to the wrong directory.

This commit fixes all three issues:
- Uses require.resolve with paths:[process.cwd()] to resolve tailwindcss
  from the user's project context first, falling back to NativeWind's own
  resolution.
- Resolves configPath relative to projectRoot when provided.
- Improves error messages with actionable guidance for monorepo users.

This branch has not been deployed

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

Labels

v4 Issue pertains to version 4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants