gluestack / gluestack-ui

React & React Native Components & Patterns (copy-paste components & patterns crafted with Tailwind CSS (NativeWind))
https://gluestack.io/
MIT License
2.76k stars 121 forks source link

Styles not being applied on a clean install #2559

Open Viraj-10 opened 2 weeks ago

Viraj-10 commented 2 weeks ago

Discussed in https://github.com/gluestack/gluestack-ui/discussions/2526

Originally posted by **Wolvinny** October 23, 2024 Hi all. First of all, i am very new to web development. I do have experience in typescript and node, but this is my first time touching web development, other than fooling around a little with React, so this might be a very simple fix but i've been stuck at this for over 6 hours at this point. Currently, i am stuck on an issue, where i can import buttons and other components just fine, but they just wont be styled. Following the [guide](https://gluestack.io/ui/docs/home/getting-started/installation), i first created an expo project (i am using, or well, trying to use react native) After that, i ran the gluestack-ui init command and added a [button](https://gluestack.io/ui/docs/components/button) (yes, i also added it using the npx command). I also tried the manual installation but this only caused more issues. Upon running the `npm start` command, and opening the web version, i am greeted with this error: `Unable to resolve module '@/global.css' from C:\Users\<>\app\app\_layout.tsx: '@/global.css' could not be found within the project or in these directories: node_modules`. This points to the lines ```ts import "'@/global.css'"; import { GluestackUIProvider } from "@/'components/ui'/gluestack-ui-provider"; ``` which for some reason have additional ' in them (again, clean install, i did not change any code) After removing those; and restarting the web server, and running the following code. ```ts import { Button, ButtonText } from "@/components/ui/button"; import React from "react"; import { View } from "react-native"; export default function Index() { return ( ); } ``` i get the following result: ![image](https://github.com/user-attachments/assets/dbc08b4d-aa89-413f-b251-1a78f3792721) None of the other components also render. I am using Node v22.9.0; react v18.2.0 and expo SDK 51.0.38 I cannot make a snack (it freezes when i upload my code) or a sandbox (it does not allow me to upload any files), but i feel this is a very simple issue that i cannot wrap my head around, nor have i seen someone with the same issue Full `npm ls` output: ``` ├── @babel/core@7.25.9 ├── @expo/vector-icons@14.0.4 ├── @gluestack-ui/button@1.0.7 ├── @gluestack-ui/nativewind-utils@1.0.23 ├── @gluestack-ui/overlay@0.1.15 ├── @gluestack-ui/toast@1.0.7 ├── @react-navigation/native@6.1.18 ├── @types/jest@29.5.14 ├── @types/react-test-renderer@18.3.0 ├── @types/react@18.2.79 ├── babel-plugin-module-resolver@5.0.2 ├── expo-constants@16.0.2 ├── expo-font@12.0.10 ├── expo-linking@6.3.1 ├── expo-router@3.5.23 ├── expo-splash-screen@0.27.6 ├── expo-status-bar@1.12.1 ├── expo-system-ui@3.0.7 ├── expo-web-browser@13.0.3 ├── expo@51.0.38 ├── jest-expo@51.0.4 ├── jest@29.7.0 ├── jscodeshift@0.15.2 ├── nativewind@4.0.36 ├── prettier@3.3.3 ├── react-dom@18.2.0 ├── react-native-gesture-handler@2.16.2 ├── react-native-reanimated@3.10.1 ├── react-native-safe-area-context@4.10.5 ├── react-native-screens@3.31.1 ├── react-native-svg@13.4.0 ├── react-native-web@0.19.13 ├── react-native@0.74.5 ├── react-test-renderer@18.2.0 ├── react@18.2.0 ├── tailwindcss@3.4.14 └── typescript@5.3.3 ```
gaofc commented 2 weeks ago

I also followed the guide and the button didn't display. Has this problem been resolved?

JackGrantham commented 2 weeks ago

Seeing the same issue. Fresh expo react native app with no changes and follow the gluestack-ui guide both using CLI and manually and styles don't display.

mithun-si commented 2 weeks ago

I am experiencing the same issue in my Next.js project and also try to applying Tailwind utility classes to the button, there is no effect on its style.

Viraj-10 commented 2 weeks ago

Hey @mithun-si , @JackGrantham @gaofc, Can you please share repo? and also which OS you are using windows or mac?

mithun-si commented 2 weeks ago

I'm using Windows

gaofc commented 2 weeks ago

I'm using Windows too.

mithun-si commented 2 weeks ago

https://codesandbox.io/p/devbox/playaround-hpfszq

this is the my code sandbox link I think that you can get idea from there and also for your information I am using next.js and npx gluestack-ui@latest init npx gluestack-ui@latest add --all command to install gluestack-ui and it's components

ryanmitchell commented 2 weeks ago

I'm seeing the same issue in an Expo project. The components work but no styling is applied.

vaibhk20 commented 2 weeks ago

Hey everyone! We've released an updated version of the CLI with bug fixes to address the reported issues. Let us know if you face any issues while using it.

mithun-si commented 2 weeks ago

Hi @vaibhk20, I am created fresh Next.js project and then install the latest gluestack-ui with this command "npx gluestack-ui@latest init" and try to used Button component but still the style is not applied

Next.js version: 14.2.16

Viraj-10 commented 2 weeks ago

Hey @mithun-si, Please add "jsxImportSource": "nativewind" to your tsconfig file.

JackGrantham commented 2 weeks ago

I am still seeing the same issue.

Here are the steps I am taking:

  1. run 'npx create-expo-app@latest --template' using the Blank Typescript template
  2. run 'npm start' to make sure the application runs as expected
  3. stop application and follow the gluestack-ui guide and start by running 'npx gluestack-ui init'
  4. run 'npm start'
  5. see issues with import of global.css and GluestackUIProvider gluestack_import_issue
  6. Remove extra single quotes from both import statements
  7. run 'npm start' ... application starts fine
  8. stop application and run 'npx gluestack-ui add button'
  9. add Button with ButtonText in App.tsx file making sure to import from './components/ui/button'
  10. run 'npm start' ... see button text rendering but no styling

I also have tried adding "jsxImportSource": "nativewind" to my tsconfig file and this did not change anything for me.

I am using Windows 11

Here is my code: https://github.com/JackGrantham/gluestackv2-test

Viraj-10 commented 2 weeks ago

Hey @JackGrantham, I have created a PR with all the fixes. Seems like cli is not working properly on windows.

Viraj-10 commented 2 weeks ago

I'm seeing the same issue in an Expo project. The components work but no styling is applied.

Hey @ryanmitchell, Can you checkout this PR and try to make same changes to it for more detailed guide please have look at nativewind docs.

ryanmitchell commented 2 weeks ago

Yeah thanks. I got it working by copying over the configs from the starter kit app.

JackGrantham commented 2 weeks ago

Thanks @Viraj-10 your changes worked. However, I did need to downgrade to Node v20 from v22 since I was running into issues with 'require' not being defined in some imports in tailwind.config.js and metro.config.js

mathis-kdio commented 2 weeks ago

Does this also work with nativewind 4.1.23?

mithun-si commented 2 weeks ago

Hey @Viraj-10 , After adding this "jsxImportSource": "nativewind" to mytsconfig file now I can use tailwindcss it's work thanks but the default behavior still not working for example

  <Button size="md" variant="outline" action="primary" >
      <ButtonText>Hello World!</ButtonText>
    </Button>

it should show a button with some outline right? but my case I only see the Hello World! text nothing else

Next.js: 14.2.16 windows: 11 pro

Viraj-10 commented 2 weeks ago

Does this also work with nativewind 4.1.23?

@mathis-kdio, We are releasing support for v4.1 this week.

2475 you can checkout all the changes here.

Viraj-10 commented 2 weeks ago

Hey @Viraj-10 , After adding this "jsxImportSource": "nativewind" to mytsconfig file now I can use tailwindcss it's work thanks but the default behavior still not working for example

  <Button size="md" variant="outline" action="primary" >
      <ButtonText>Hello World!</ButtonText>
    </Button>

it should show a button with some outline right? but my case I only see the Hello World! text nothing else

Next.js: 14.2.16 windows: 11 pro

@mithun-si please check your content property in tailwind.config.js file. give proper path to all the components and pages. checkout guide from tailwind here

mithun-si commented 2 weeks ago

Hey @Viraj-10 , After adding this "jsxImportSource": "nativewind" to mytsconfig file now I can use tailwindcss it's work thanks but the default behavior still not working for example

  <Button size="md" variant="outline" action="primary" >
      <ButtonText>Hello World!</ButtonText>
    </Button>

it should show a button with some outline right? but my case I only see the Hello World! text nothing else Next.js: 14.2.16 windows: 11 pro

@mithun-si please check your content property in tailwind.config.js file. give proper path to all the components and pages. checkout guide from tailwind here

Thanks @Viraj-10 it's working now but for action="primary"/"secondary" the color is not shown why? is there anything else need to add to show color I am using gluestack-ui CLI also when I am building my Next.js application there is a lot's of type related warning and error and that's why application build is failed please solve this ASAP and If I use //@ts-ignore for where need type I can successfully build application so if I use //@ts-ignore is there any problem arise in future?

miguel93041 commented 2 days ago

@Viraj-10 Any updates on when #2475 will be released? Nativewind 4.1 supposedly addresses https://github.com/nativewind/nativewind/issues/924, which has been a major hassle for both production and development.

Viraj-10 commented 2 days ago

@miguel93041 you can install v4.1 with --alpha flag in CLI. we announced it yesterday on discord and twitter.

ray-so-export (1)