Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind CSS with Next.js not applicable

Introduced Tailwind CSS to the Next.js environment.
I want to apply color.lime, but I get the following error.

./node_modules/tailwindcss/tailwind.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-5-1!./node_modules/next/dist/compiled/postcss-loader/cjs.js??ref--5-oneOf-5-2!./node_modules/tailwindcss/tailwind.css)
ReferenceError: color is not defined

tailwind.config.js

const colors = require(`tailwindcss/colors`);
module.exports = {
  purge: ["./src/**/*.{js,ts,jsx,tsx}"],
  darkMode: false, // 'media' or 'class'
  theme: { extend: { colors: { lime: color.lime } } },
  variants: { extend: {} },
  plugins: [],
};

__app.tsx

import "tailwindcss/tailwind.css";
import type { AppProps } from "next/app";
import Head from "next/head";

const App = (props: AppProps) => {
  return (
    <>
      <Head>
        <title>nexst</title>
      </Head>
      <props.Component {...props.pageProps} />
    </>
  );
};

// eslint-disable-next-line import/no-default-export
export default App;
like image 511
sato desu Avatar asked Oct 28 '25 15:10

sato desu


1 Answers

You have a typo in your tailwind.config.js, you should access the color with colors.lime rather than color.lime.

const colors = require(`tailwindcss/colors`);
module.exports = {
    purge: ["./src/**/*.{js,ts,jsx,tsx}"],
    darkMode: false, // 'media' or 'class'
    theme: { extend: { colors: { lime: colors.lime } } }, // here use `colors`
    variants: { extend: {} },
    plugins: [],
};
like image 130
juliomalves Avatar answered Oct 30 '25 13:10

juliomalves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!