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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/cli/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ export const dependencyVersionMap = {
"@opennextjs/cloudflare": "^1.3.0",
"nitro-cloudflare-dev": "^0.2.2",
"@sveltejs/adapter-cloudflare": "^7.0.4",

// TailwindCSS and related dependencies
autoprefixer: "^10.4.21",
postcss: "^8.5.6",
tailwindcss: "^3.4.17",
Comment on lines +121 to +124
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.

} as const;

export type AvailableDependencies = keyof typeof dependencyVersionMap;
Expand Down
2 changes: 2 additions & 0 deletions apps/cli/src/helpers/project-generation/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { setupAuth } from "../setup/auth-setup";
import { setupBackendDependencies } from "../setup/backend-setup";
import { setupDatabase } from "../setup/db-setup";
import { setupExamples } from "../setup/examples-setup";
import { setupFrontendDependencies } from "../setup/frontend-setup";
import {
generateCloudflareWorkerTypes,
setupRuntime,
Expand Down Expand Up @@ -42,6 +43,7 @@ export async function createProject(options: ProjectConfig) {

await copyBaseTemplate(projectDir, options);
await setupFrontendTemplates(projectDir, options);
await setupFrontendDependencies(options);
await setupBackendFramework(projectDir, options);
if (!isConvex) {
await setupDbOrmTemplates(projectDir, options);
Expand Down
38 changes: 38 additions & 0 deletions apps/cli/src/helpers/setup/frontend-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import consola from "consola";
import pc from "picocolors";
import type { ProjectConfig } from "../../types";
import { addPackageDependency } from "../../utils/add-package-deps";

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");
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.


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");
}
}
3 changes: 3 additions & 0 deletions apps/cli/templates/frontend/native/nativewind/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ config.resolver.unstable_enablePackageExports = true;

config.resolver.disableHierarchicalLookup = true;

// Ensure local node_modules takes precedence
config.resolver.resolverMainFields = ["react-native", "browser", "main"];

module.exports = config;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"devDependencies": {
"@babel/core": "^7.26.10",
"@types/react": "~19.0.10",
"tailwindcss": "^3.4.17",
"tailwindcss": "3.4.17",
"typescript": "~5.8.2"
},
"private": true
Expand Down
2 changes: 1 addition & 1 deletion bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"apps/cli": {
"name": "create-better-t-stack",
"version": "2.28.3",
"version": "2.28.5",
"bin": {
"create-better-t-stack": "dist/index.js",
},
Expand Down