Tailwind would not load in a new nextjs app... Unexpected character '@'

43 Views Asked by At

I used the "create-next-app" to make my new Nextjs project. I selected tailwindcss in the installer, but when I try to run app with npm run dev, Ill get this error:

Module parse failed: Unexpected character '@' (1:0)
> @import 'tailwindcss/base';
| @import 'tailwindcss/components';
| @import 'tailwindcss/utilities';

I hope there are smart people out there that can give me answer... :)

I will paste the code below:

Layout.js:

import { Inter } from "next/font/google";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

export const metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body className={inter.className}>{children}</body>
    </html>
  );
}

page.js:

import Image from "next/image";

export default function Home() {
  return (
    <>
      <h1>Hello world</h1>
    </>
  );
}

next.config.mjs

/** @type {import('next').NextConfig} */
const nextConfig = {};


export default nextConfig;

Edit: Tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./components/**/*.{js,ts,jsx,tsx,mdx}",
    "./app/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    extend: {
      backgroundImage: {
        "gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
        "gradient-conic":
          "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
      },
    },
  },
  plugins: [],
};

New edit:

Error: enter image description here

Packages: { "name": "camping-fullstack", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "next": "14.1.4", "react": "^18", "react-dom": "^18" }, "devDependencies": { "autoprefixer": "^10.4.19", "eslint": "^8", "eslint-config-next": "14.1.4", "postcss": "^8.4.38", "tailwindcss": "^3.4.3" } }

1

There are 1 best solutions below

1
Andrew On

That error seems odd, because imports should be allowed, but it's possible that it's just an inaccurate message. What you're looking for in this case isn't an import, it's a directive that Tailwind itself supplies:

@tailwind base;
@tailwind components;
@tailwind utilities;