Skip to content

fix: nativewind support tailwind css v3 for native app #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JasrajChouhan
Copy link
Contributor

@JasrajChouhan JasrajChouhan commented Aug 1, 2025

Fix: #454

Enable the support the tailwind v3 for nativewind (native apps).

Core fix step

Root node_modules support the v4 for tailwind css which is good for others app but for nativewind it is not good.
So we need to install some tailwind depd in root and handle correclty and
Ensure local node_modules takes precedence.

See the all screenshots carefully.
Screenshot_20250801_230326
Screenshot_20250801_230354
Screenshot_20250801_230432-1
Screenshot_20250801_232443_Expo Go

Screenshot_20250801_230410 Screenshot_20250801_230432

Testing Env

  • OS : Arch Linux
  • Browser : Firefox
  • Mobile OS : Android (expo go app )

Summary by CodeRabbit

  • New Features

    • Frontend project creation now automatically sets up TailwindCSS and related dependencies when using the "native-nativewind" option.
    • Improved Metro bundler configuration for native projects to enhance module resolution.
  • Chores

    • TailwindCSS and related dependencies are now included with specific versioning for consistency.
    • TailwindCSS dependency in the template is now pinned to an exact version for improved reliability.

Copy link

changeset-bot bot commented Aug 1, 2025

⚠️ No Changeset found

Latest commit: 52a89f9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Aug 1, 2025

Walkthrough

This change introduces a new helper function to set up TailwindCSS-related dependencies for projects using the "native-nativewind" frontend option. It ensures the correct versions of TailwindCSS, autoprefixer, and postcss are added, updates the Metro bundler config for module resolution, and pins the TailwindCSS version in the template.

Changes

Cohort / File(s) Change Summary
Dependency Version Constants
apps/cli/src/constants.ts
Added TailwindCSS, autoprefixer, and postcss version entries to dependencyVersionMap.
Frontend Dependency Setup Logic
apps/cli/src/helpers/setup/frontend-setup.ts
Introduced setupFrontendDependencies for adding TailwindCSS-related dependencies conditionally.
Project Generation Integration
apps/cli/src/helpers/project-generation/create-project.ts
Integrated setupFrontendDependencies into the project creation flow.
Metro Bundler Config Update
apps/cli/templates/frontend/native/nativewind/metro.config.js
Added resolverMainFields to Metro config to prioritize entry point resolution for React Native.
Template Tailwind Version Pinning
apps/cli/templates/frontend/native/nativewind/package.json.hbs
Changed TailwindCSS devDependency from a range to an exact version ("3.4.17").

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant FrontendSetup
    participant PackageManager

    User->>CLI: Run project creation command
    CLI->>FrontendSetup: setupFrontendTemplates(...)
    CLI->>FrontendSetup: setupFrontendDependencies(options)
    FrontendSetup->>PackageManager: add TailwindCSS, autoprefixer, postcss (if native-nativewind)
    PackageManager-->>FrontendSetup: Dependency installation result
    FrontendSetup-->>CLI: Setup complete
    CLI->>CLI: Continue with backend and other setup
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Assessment against linked issues

Objective Addressed Explanation
Ensure NativeWind uses Tailwind CSS v3 only (#454)
Add TailwindCSS, autoprefixer, postcss dependencies for native-nativewind (#454)
Pin TailwindCSS version in template for native-nativewind (#454)
Update Metro config for correct module resolution with NativeWind (#454)

Poem

A bunny hops with code so neat,
Tailwind v3 now takes its seat!
Dependencies set with gentle care,
Metro resolves with native flair.
No more errors, just delight—
The stack is ready, working right!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Aug 1, 2025

Open in StackBlitz

npx https://pkg.pr.new/AmanVarshney01/create-better-t-stack@455

commit: 52a89f9

Copy link
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: 2

🧹 Nitpick comments (1)
apps/cli/src/helpers/setup/frontend-setup.ts (1)

11-11: Remove unused variable or implement unistyles logic.

The hasUnistyles variable is declared but never used in the function logic. Either implement the handling for unistyles or remove this variable to clean up the code.

-	const hasUnistyles = frontend.includes("native-unistyles");

Or if unistyles support is planned, consider adding the logic:

 	if (hasNativeWind) {
 		// existing nativewind logic...
+	} else if (hasUnistyles) {
+		// TODO: Add unistyles dependency setup
 	} else {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cef5840 and 1fcd6a8.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • apps/cli/src/constants.ts (1 hunks)
  • apps/cli/src/helpers/project-generation/create-project.ts (2 hunks)
  • apps/cli/src/helpers/setup/frontend-setup.ts (1 hunks)
  • apps/cli/templates/frontend/native/nativewind/metro.config.js (1 hunks)
  • apps/cli/templates/frontend/native/nativewind/package.json.hbs (1 hunks)
  • apps/cli/test-nativewind (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Vijayabaskar56
PR: AmanVarshney01/create-better-t-stack#310
File: apps/cli/templates/frontend/angular/src/app.component.html:1-7
Timestamp: 2025-06-08T17:57:33.083Z
Learning: The Angular frontend template uses Tailwind CSS v4, which doesn't require a traditional tailwind.config.js configuration file.
📚 Learning: the angular frontend template uses tailwind css v4, which doesn't require a traditional tailwind.con...
Learnt from: Vijayabaskar56
PR: AmanVarshney01/create-better-t-stack#310
File: apps/cli/templates/frontend/angular/src/app.component.html:1-7
Timestamp: 2025-06-08T17:57:33.083Z
Learning: The Angular frontend template uses Tailwind CSS v4, which doesn't require a traditional tailwind.config.js configuration file.

Applied to files:

  • apps/cli/templates/frontend/native/nativewind/package.json.hbs
  • apps/cli/src/helpers/setup/frontend-setup.ts
  • apps/cli/src/constants.ts
🪛 Biome (2.1.2)
apps/cli/src/helpers/setup/frontend-setup.ts

[error] 11-11: This variable hasUnistyles is unused.

Unused variables are often the result of an incomplete refactoring, typos, or other sources of bugs.
Unsafe fix: If this is intentional, prepend hasUnistyles with an underscore.

(lint/correctness/noUnusedVariables)

🔇 Additional comments (6)
apps/cli/test-nativewind (1)

1-1: Review comment not applicable – no Git submodule detected
The apps/cli/test-nativewind directory is a regular folder (no .gitmodules or .git inside), and there’s no submodule or raw-commit pointer in this PR. Please disregard the submodule setup recommendation.

Likely an incorrect or invalid review comment.

apps/cli/templates/frontend/native/nativewind/package.json.hbs (1)

45-45: LGTM! Version pinning addresses NativeWind compatibility.

Pinning tailwindcss to the exact version 3.4.17 is the correct approach to ensure NativeWind compatibility, as mentioned in the PR objectives that "NativeWind only supports Tailwind CSS v3". This prevents version conflicts that could arise from caret ranges.

apps/cli/templates/frontend/native/nativewind/metro.config.js (1)

20-22: LGTM! Metro resolver config supports local dependency precedence.

The resolverMainFields configuration correctly prioritizes react-native field resolution, which aligns with the PR's strategy to ensure local node_modules take precedence over root ones. This helps resolve the Tailwind CSS version conflict between root (v4) and local (v3) installations.

apps/cli/src/helpers/project-generation/create-project.ts (2)

35-35: LGTM! Clean import addition.

The import is properly structured and follows the existing import organization pattern.


46-46: LGTM! Well-positioned dependency setup.

The placement of setupFrontendDependencies(options) immediately after setupFrontendTemplates is logical and ensures frontend dependencies are configured early in the project creation flow, before backend setup begins.

apps/cli/src/helpers/setup/frontend-setup.ts (1)

17-34: LGTM! Solid dependency management with proper error handling.

The core functionality correctly adds TailwindCSS dependencies (autoprefixer, postcss, tailwindcss) to the root package.json when NativeWind is detected. The error handling and logging provide good visibility into the process.

Comment on lines +121 to +124
// TailwindCSS and related dependencies
autoprefixer: "^10.4.21",
postcss: "^8.5.6",
tailwindcss: "^3.4.17",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Pin exact Tailwind version and correct PostCSS release to avoid install failures

  1. postcss@8.5.6 has not been published on npm (latest 8.x is 8.4.x). Trying to install it will break project generation.
  2. NativeWind is extremely sensitive to the exact Tailwind major and minor version. Using ^3.4.17 risks silently bumping to 3.5/3.6 once they are released and re-introducing the incompatibility we’re fixing.
-	autoprefixer: "^10.4.21",
-	postcss: "^8.5.6",
-	tailwindcss: "^3.4.17",
+	autoprefixer: "10.4.21",
+	postcss: "8.4.35",
+	tailwindcss: "3.4.17",

Pinning all three to published, known-good versions guarantees reproducible scaffolding across package managers and CI.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TailwindCSS and related dependencies
autoprefixer: "^10.4.21",
postcss: "^8.5.6",
tailwindcss: "^3.4.17",
// TailwindCSS and related dependencies
autoprefixer: "10.4.21",
postcss: "8.4.35",
tailwindcss: "3.4.17",
🤖 Prompt for AI Agents
In apps/cli/src/constants.ts around lines 121 to 124, the versions for postcss
and tailwindcss are not pinned to exact, published versions, which can cause
install failures and compatibility issues. Change the postcss version to the
latest published 8.x version (e.g., 8.4.x) and pin tailwindcss to the exact
known-good version (e.g., 3.4.17 without the caret) to prevent automatic minor
or patch upgrades. Also, pin autoprefixer to an exact version to ensure
consistent dependency resolution.

Comment on lines 6 to 38
export async function setupFrontendDependencies(config: ProjectConfig) {
const { frontend, projectDir } = config;

// Check if nativewind is being used
const hasNativeWind = frontend.includes("native-nativewind");
const hasUnistyles = frontend.includes("native-unistyles");

consola.info(`Frontend: ${frontend.join(", ")}`);
consola.info(`Has NativeWind: ${hasNativeWind}`);
consola.info(`Project Dir: ${projectDir}`);

if (hasNativeWind) {
try {
consola.info("Adding TailwindCSS dependencies...");
// Add TailwindCSS and related dependencies to root package.json
await addPackageDependency({
devDependencies: ["autoprefixer", "postcss", "tailwindcss"],
projectDir,
});

consola.success(
pc.green("Added TailwindCSS dependencies to root package.json"),
);
} catch (error) {
consola.error(pc.red("Failed to add TailwindCSS dependencies"));
if (error instanceof Error) {
consola.error(pc.red(error.message));
}
}
} else {
consola.info("NativeWind not detected, skipping TailwindCSS dependencies");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify dependency versions are defined in constants.

Ensure that the dependencies being added (autoprefixer, postcss, tailwindcss) have their versions properly defined in the dependencyVersionMap constant, as mentioned in the AI summary.


🏁 Script executed:

#!/bin/bash
# Verify that TailwindCSS dependencies have versions defined in constants
ast-grep --pattern 'dependencyVersionMap = {
  $$$
}'

Length of output: 55


🏁 Script executed:

#!/bin/bash
# Search for dependencyVersionMap constant definition across the codebase
rg --color=never "dependencyVersionMap" -n

Length of output: 514


🏁 Script executed:

#!/bin/bash
# Display the dependencyVersionMap entries to verify TailwindCSS dependencies
sed -n '30,100p' apps/cli/src/constants.ts

Length of output: 1395


🏁 Script executed:

#!/bin/bash
# Check if TailwindCSS dependencies have versions defined in dependencyVersionMap
rg --color=never -n '"autoprefixer"' apps/cli/src/constants.ts
rg --color=never -n '"postcss"'       apps/cli/src/constants.ts
rg --color=never -n '"tailwindcss"'   apps/cli/src/constants.ts

Length of output: 188


Add missing TailwindCSS dependency versions to dependencyVersionMap

The dependencyVersionMap in apps/cli/src/constants.ts currently lacks entries for autoprefixer, postcss, and tailwindcss. Since addPackageDependency looks up versions from this map, you should add these keys with their desired versions to avoid undefined–version errors.

• File: apps/cli/src/constants.ts
Insert within the dependencyVersionMap object (around line 30):

"autoprefixer": "<your-version-here>",
"postcss":      "<your-version-here>",
"tailwindcss":  "<your-version-here>",

• Ensure the chosen versions match the TailwindCSS setup requirements for your project.

🧰 Tools
🪛 Biome (2.1.2)

[error] 11-11: This variable hasUnistyles is unused.

Unused variables are often the result of an incomplete refactoring, typos, or other sources of bugs.
Unsafe fix: If this is intentional, prepend hasUnistyles with an underscore.

(lint/correctness/noUnusedVariables)

🤖 Prompt for AI Agents
In apps/cli/src/constants.ts around line 30, the dependencyVersionMap object is
missing entries for autoprefixer, postcss, and tailwindcss, which are required
by the setupFrontendDependencies function. Add these three keys to
dependencyVersionMap with appropriate version strings that match your project's
TailwindCSS setup requirements to ensure addPackageDependency can resolve their
versions correctly and avoid undefined version errors.

Copy link
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

♻️ Duplicate comments (1)
apps/cli/src/helpers/setup/frontend-setup.ts (1)

17-37: Verify dependency versions are defined in constants.

The logic flow is well-structured with proper error handling. However, ensure that the dependencies being added (autoprefixer, postcss, tailwindcss) have their versions properly defined in the dependencyVersionMap constant, as mentioned in previous reviews.

Please verify that these dependencies have version entries in the constants file:

#!/bin/bash
# Check if TailwindCSS dependencies have versions defined in dependencyVersionMap
rg -n '"autoprefixer"' apps/cli/src/constants.ts
rg -n '"postcss"' apps/cli/src/constants.ts  
rg -n '"tailwindcss"' apps/cli/src/constants.ts
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1fcd6a8 and 52a89f9.

📒 Files selected for processing (2)
  • apps/cli/src/helpers/project-generation/create-project.ts (2 hunks)
  • apps/cli/src/helpers/setup/frontend-setup.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/cli/src/helpers/project-generation/create-project.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Vijayabaskar56
PR: AmanVarshney01/create-better-t-stack#310
File: apps/cli/templates/frontend/angular/src/app.component.html:1-7
Timestamp: 2025-06-08T17:57:33.083Z
Learning: The Angular frontend template uses Tailwind CSS v4, which doesn't require a traditional tailwind.config.js configuration file.
📚 Learning: the angular frontend template uses tailwind css v4, which doesn't require a traditional tailwind.con...
Learnt from: Vijayabaskar56
PR: AmanVarshney01/create-better-t-stack#310
File: apps/cli/templates/frontend/angular/src/app.component.html:1-7
Timestamp: 2025-06-08T17:57:33.083Z
Learning: The Angular frontend template uses Tailwind CSS v4, which doesn't require a traditional tailwind.config.js configuration file.

Applied to files:

  • apps/cli/src/helpers/setup/frontend-setup.ts
🪛 Biome (2.1.2)
apps/cli/src/helpers/setup/frontend-setup.ts

[error] 11-11: This variable hasUnistyles is unused.

Unused variables are often the result of an incomplete refactoring, typos, or other sources of bugs.
Unsafe fix: If this is intentional, prepend hasUnistyles with an underscore.

(lint/correctness/noUnusedVariables)

🔇 Additional comments (3)
apps/cli/src/helpers/setup/frontend-setup.ts (3)

1-4: LGTM!

The imports are clean and all appear to be used appropriately in the function implementation.


6-8: LGTM!

The function signature is well-defined with proper typing, and the destructuring approach cleanly extracts the required configuration properties.


13-16: LGTM!

The logging statements provide excellent visibility into the function's operation and will be helpful for debugging and monitoring the setup process.


// Check if nativewind is being used
const hasNativeWind = frontend.includes("native-nativewind");
const hasUnistyles = frontend.includes("native-unistyles");
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unused variable or implement Unistyles support.

The hasUnistyles variable is defined but never used in the function. Either remove it if Unistyles support isn't planned, or implement the corresponding logic.

-	const hasUnistyles = frontend.includes("native-unistyles");

Alternatively, if Unistyles support is planned, consider implementing similar dependency setup logic for it.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const hasUnistyles = frontend.includes("native-unistyles");
🧰 Tools
🪛 Biome (2.1.2)

[error] 11-11: This variable hasUnistyles is unused.

Unused variables are often the result of an incomplete refactoring, typos, or other sources of bugs.
Unsafe fix: If this is intentional, prepend hasUnistyles with an underscore.

(lint/correctness/noUnusedVariables)

🤖 Prompt for AI Agents
In apps/cli/src/helpers/setup/frontend-setup.ts at line 11, the variable
hasUnistyles is declared but never used. To fix this, either remove the
hasUnistyles declaration if Unistyles support is not intended, or implement the
necessary logic to handle Unistyles dependencies similarly to other frontend
options if support is planned.

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.

Error: NativeWind only supports Tailwind CSS v3
1 participant