shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
74.15k stars 4.58k forks source link

[bug]: tailwind.config.ts malformed after installing components #4841

Open niyrme opened 1 month ago

niyrme commented 1 month ago

Describe the bug

after a clean project setup I added many of the shadcn components and the resulting tailwind.config.ts file was slightly malformed.

import type { Config } from "tailwindcss";

export default {
    darkMode: ["class"],
    content: ["./app/**/{**,.client,.server}/**/*.{js,jsx,ts,tsx}"],
  theme: {
    extend: {
        fontFamily: {
            sans: [\\n          'Inter"',\\n          "ui-sans-serif",\\n          "system-ui",\\n          "sans-serif",\\n          'Apple Color Emoji"',\\n          'Segoe UI Emoji"',\\n          'Segoe UI Symbol"',\\n          'Noto Color Emoji"',\\n        ]
        },
        borderRadius: {
            lg: 'var(--radius)',
            md: 'calc(var(--radius) - 2px)',
            sm: 'calc(var(--radius) - 4px)'
        },
        colors: {
            background: 'hsl(var(--background))',
            foreground: 'hsl(var(--foreground))',
            card: {
                DEFAULT: 'hsl(var(--card))',
                foreground: 'hsl(var(--card-foreground))'
            },
            popover: {
                DEFAULT: 'hsl(var(--popover))',
                foreground: 'hsl(var(--popover-foreground))'
            },
            primary: {
                DEFAULT: 'hsl(var(--primary))',
                foreground: 'hsl(var(--primary-foreground))'
            },
            secondary: {
                DEFAULT: 'hsl(var(--secondary))',
                foreground: 'hsl(var(--secondary-foreground))'
            },
            muted: {
                DEFAULT: 'hsl(var(--muted))',
                foreground: 'hsl(var(--muted-foreground))'
            },
            accent: {
                DEFAULT: 'hsl(var(--accent))',
                foreground: 'hsl(var(--accent-foreground))'
            },
            destructive: {
                DEFAULT: 'hsl(var(--destructive))',
                foreground: 'hsl(var(--destructive-foreground))'
            },
            border: 'hsl(var(--border))',
            input: 'hsl(var(--input))',
            ring: 'hsl(var(--ring))',
            chart: {
                '1': 'hsl(var(--chart-1))',
                '2': 'hsl(var(--chart-2))',
                '3': 'hsl(var(--chart-3))',
                '4': 'hsl(var(--chart-4))',
                '5': 'hsl(var(--chart-5))'
            }
        },
        keyframes: {
            'accordion-down': {
                from: {
                    height: '0'
                },
                to: {
                    height: 'var(--radix-accordion-content-height)'
                }
            },
            'accordion-up': {
                from: {
                    height: 'var(--radix-accordion-content-height)'
                },
                to: {
                    height: '0'
                }
            }
        },
        animation: {
            'accordion-down': 'accordion-down 0.2s ease-out',
            'accordion-up': 'accordion-up 0.2s ease-out'
        }
    }
  },
  plugins: [require("tailwindcss-animate")],
} satisfies Config;

Affected component/components

can't say for sure if it's just one, or a combination of many

How to reproduce

  1. Create remix app from template npx create-remix@2.11.2 1.1. name: 1.2. git repository: no 1.3. "install dependencies": yes
  2. npx shadcn@2.0.3 init 2.1. style: default 2.2. base color: slate 2.3. css variables: yes
  3. add components (happens both inline and interactive) 3.1. npx shadcn@2.0.3 add accordion alert-dialog avatar badge button calendar card carousel checkbox dialog drawer input input-otp label pagination progress radio-group scroll-area select separator sheet skeleton slider switch table tabs textarea toast toggle toggle-group tooltip 3.2. skip/decline both button and toggle overwrite messages

Codesandbox/StackBlitz link

https://codesandbox.io/p/devbox/43jndj

Logs

No response

System Info

OS: Windows 10 Pro x64; Version 22H2; Build 19045.4894
Bun 1.1.27-canary.33+6faf657e3
`npx shadcn@latest --version` is `2.0.3` (pinned in reproduction)
`npx create-remix@latest --version` is `2.11.2` (pinned in reproduction)

Before submitting

hinsxd commented 1 month ago

I have pinpointed the issue to be function parseValue(node: any): any reading assuming the wrong type and reading the wrong field.

I thought I fixed the problem but it seems that if the AST node are treated as correct types, parsing the object first is not a viable option because it cannot handle spread syntax. The only way would be traverse through the AST and replace the value one by one.

WIP: https://github.com/shadcn-ui/ui/pull/4851

cosn commented 1 month ago

+1 to fixing this, but the other, larger issue I've faced is that after fixing this and following the Remix install steps, I get the following error when trying to build:

app/root.tsx (10:7): "default" is not exported by "app/tailwind.css", imported by "app/root.tsx".
file: my-app/app/root.tsx:10:7

 8: import type { LinksFunction } from "@remix-run/node";
 9:
10: import styles from "./tailwind.css";
           ^
11:
12: export const links: LinksFunction = () => [

Anyone else encounter this? The error is on a pure vanilla Remix project and fresh shadcn init.

cosn commented 1 month ago

Figured it out, the issue is taht the import should be:

import styles from "./tailwind.css?url";