ui icon indicating copy to clipboard operation
ui copied to clipboard

postcss reports an error on fontFamily.sans when using typescript in a react app

Open ymolists opened this issue 2 years ago • 1 comments

Hi all.

Thank you so much for making this utility !

I am trying to use shadcn in a vite react application (as opposed to next) and i am encountering this issue. I tried turning my config file to typescript. This error does not happen if i dont use typescript for the config file.

import type { Config } from "tailwindcss";

import fontFamily from "tailwindcss/defaultTheme";
import animatePlugin from "tailwindcss-animate";

const config = {
  darkMode: ["class"],
  content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
  theme: {
    container: {
      center: true,
      padding: "2rem",
      screens: {
        "2xl": "1400px",
      },
    },
    extend: {
      colors: {
        border: "hsl(var(--border))",
        input: "hsl(var(--input))",
        ring: "hsl(var(--ring))",
        background: "hsl(var(--background))",
        foreground: "hsl(var(--foreground))",
        primary: {
          DEFAULT: "hsl(var(--primary))",
          foreground: "hsl(var(--primary-foreground))",
        },
        secondary: {
          DEFAULT: "hsl(var(--secondary))",
          foreground: "hsl(var(--secondary-foreground))",
        },
        destructive: {
          DEFAULT: "hsl(var(--destructive))",
          foreground: "hsl(var(--destructive-foreground))",
        },
        muted: {
          DEFAULT: "hsl(var(--muted))",
          foreground: "hsl(var(--muted-foreground))",
        },
        accent: {
          DEFAULT: "hsl(var(--accent))",
          foreground: "hsl(var(--accent-foreground))",
        },
        popover: {
          DEFAULT: "hsl(var(--popover))",
          foreground: "hsl(var(--popover-foreground))",
        },
        card: {
          DEFAULT: "hsl(var(--card))",
          foreground: "hsl(var(--card-foreground))",
        },
      },
      borderRadius: {
        lg: `var(--radius)`,
        md: `calc(var(--radius) - 2px)`,
        sm: "calc(var(--radius) - 4px)",
      },
      fontFamily: {
        sans: ["var(--font-sans)", ...fontFamily.sans],
      },
      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: [animatePlugin],
};

export default config;

[postcss] _defaultTheme2.default.sans is not iterable
10:05:02 a.m. [vite] Internal server error: [postcss] _defaultTheme2.default.sans is not iterable
  Plugin: vite:css
  File: /projects/react/test00/src/app/app.css
      at /projects/react/test00/tailwind.config.ts:77:62
      at jiti (/projects/react/test00/node_modules/.pnpm/[email protected]/node_modules/jiti/dist/jiti.js:1:245784)
      at /projects/react/test00/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/lib/lib/load-config.js:37:30
      at loadConfig (/projects/react/test00/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/lib/lib/load-config.js:39:6)
      at getTailwindConfig (/projects/react/test00/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/lib/lib/setupTrackingContext.js:71:116)
      at /projects/react/test00/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/lib/lib/setupTrackingContext.js:99:92
      at /projects/react/test00/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/lib/processTailwindFeatures.js:48:11
      at plugins (/projects/react/test00/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/lib/plugin.js:38:63)
      at LazyResult.runOnRoot (/projects/react/test00/node_modules/.pnpm/[email protected]/node_modules/postcss/lib/lazy-result.js:339:16)
      at LazyResult.runAsync (/projects/react/test00/node_modules/.pnpm/[email protected]/node_modules/postcss/lib/lazy-result.js:393:26)

ymolists avatar Jun 16 '23 14:06 ymolists

You imported the whole tailwind theme as fontFamily.

Change this line:

import fontFamily from "tailwindcss/defaultTheme";

To this:

import { fontFamily } from "tailwindcss/defaultTheme";

This imports only the fontFamily object which contains sans. All should work normally now.

dan5py avatar Jun 16 '23 16:06 dan5py

You are a hero. Never would have found that by the error message alone.

Syntarex avatar May 03 '24 22:05 Syntarex

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Jun 29 '24 23:06 shadcn