Encountering a problem with Tailwind not loading in a fresh Next.js application, with the error message indicating an unexpected character '@'

After using "create-next-app" to kickstart my latest Nextjs project and selecting tailwindcss in the installer, I encountered an unexpected error when trying to run the app with npm run dev:

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

Seeking guidance from knowledgeable individuals out there who may have a solution... :)

Below you'll find excerpts from the code:

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" } }

Answer №1

Encountered a similar problem myself. Turns out, the issue stemmed from an unexpected NODE_ENV value that had been configured in an unconventional manner. Simply running NODE_ENV=development in your terminal should likely resolve the situation.

Answer №2

It seems like there may be an error with the import feature, even though imports are typically allowed. It's possible that this error message is just misleading. In this situation, what you actually need is not an import statement, but a directive provided by Tailwind itself:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize jQuery to dynamically swap out a CSS stylesheet in response to changes in the body class

In the head section of my HTML, I have the following stylesheet: <link rel="stylesheet" href="/templates/jooswatch-v3-5/css/bootswatch/superhero/bootstrap.min.css"> I want to replace this stylesheet with different ones based on changes in the body# ...

What could be causing the .slideToggle method to not function properly in jQuery?

Having some trouble with this code snippet: <div class="chat" style="display: none;"> <input type="text" class="chat-name" placeholder="Enter your name"> <div class="chat-messages"></div> <textarea class="chat-textar ...

What is the best way to access the values associated with the keys in an array of objects?

I have an array of objects that has the following structure: import icon1 from '!!raw-loader!../../../icon1.svg'; import icon2 from '!!raw-loader!../../../icon2.svg'; import icon3 from '!!raw-loader!../../../icon3.svg'; import ...

What is the best way to show multiple markers using react-google-maps?

Can anyone help me figure out how to display multiple markers using the react-google-maps npm package? I've been following a demo that shows how to display one map marker, but when I try to add a second marker element, it doesn't show up on the m ...

Is it possible to display or hide a spinner within a span using Javascript and AJAX?

When submitting a contact form, I want to display and hide a spinner on the submit button. The spinner should be visible while the form is being submitted and hidden once the submission is complete. Below is the code for my submit button with the spinner: ...

Prevent Copying, Defining, or Sharing in iOS Safari Selections

A Cordova App has been developed using Angular JS, with the Apple webview copy/share/define menu disabled from the view code in Xcode to prevent it from popping up. The Angular JS code is also available on a website accessible by desktops, where the Copy/ ...

Disabling the <A> tag within an image due to image map functionality

My thumbnails are set up to be different links, usually accomplished with this code: <a href=#><img src=# /></a> However, I have now converted each thumbnail into an image map (changing the thumbnail as you mouse over). Despite my attem ...

Could anyone provide guidance on how to bypass the same origin policy effectively while working with Dashcode? I'm feeling a bit confused

After exploring various recommendations on overcoming the same-origin policy, I am still unsure about the best approach to take when working with dashcode. If you have any insights or tips on how to successfully implement this, please share them! ...

Having Trouble with the Spacing Between Navbar and Page Content in Bootstrap?

Let's tackle the issue at hand: Here is the code snippet. A lot of it has been borrowed from examples and tutorials. <!-- Navigation --> <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <!-- Brand a ...

I am experiencing difficulty with inputting the data into the MySQL database

I have been encountering an error every time I try to input these values into the database. I suspect that the issue lies within this section of the code, but I am unable to pinpoint it. Can someone please assist me in identifying and resolving the error ...

Typescript does not produce unused members

Having an issue with the JS code that TypeScript compiler is generating. Here's an example class: // Class export class UserDTO { Id: number; FirstName: string; LastName: string; DateOfBirth: Date; getFullName(): string { ...

Question: How can I use the jQuery datepicker to ensure that the selected date remains in the

I recently created a webpage using a combination of HTML, PHP, and jQuery. The PHP script is designed to load all data where the date matches the one selected in the text input field generated by the jQuery datepicker. However, I encountered a problem whe ...

implementing geolocation using jquery and javascript

I am currently learning JavaScript and experimenting with the geolocation function in my HTML and PHP code, following a tutorial like this one. Here is the code snippet I added to my custom.js file: $(document).ready(function() { 'use strict&apos ...

Oops! Before proceeding, make sure to call TestBed.initTestEnvironment() first

Currently, I am experimenting with testing a service in Angular. Below is the code snippet I am working on: describe('AddressService', () => { let service: AddressService; let injector: TestBed; let httpTestingController: HttpTesting ...

Renew the id_token in the front-end: Angular 4

I am currently utilizing the ng2-adal npm library to create id_token and access_token. As the id_token is valid for 30 minutes and the access_token for 60 minutes, my goal is to automatically refresh the id_token every 20 minutes in the background. One pot ...

Automatic Update Division in Jade Template (Node.js/Express)

In my development project using Node.js, Express, Jade, and Redis, I have successfully created an app that pulls telnet stream data from reversebeacon.net. This data is then cross-referenced with Redis databases containing amateur radio club member informa ...

React together with TypeScript presents a challenge where the scroll event type is not compatible with window.addEventListener

Could it be that TypeScript DOM event types and React Event types are not compatible with each other? Consider this code snippet: useEffect(() => { const onScroll = (event: React.ChangeEvent<Body>) => { console.log("event" ...

Align columns responsively with Bootstrap and center overlay image

Experiencing issues with aligning responsive divs using Bootstrap. Here is the code in question: <div class="container-fluid"> <div class="row"> <div class="col-xl-5"> <img src=&quo ...

Angular JS Profile Grid: Discover the power of Angular JS

I came across an interesting example that caught my attention: http://www.bootply.com/fzLrwL73pd This particular example utilizes the randomUser API to generate random user data and images. I would like to create something similar, but with manually ente ...

Unable to keep the ribbon edges in place on the top

After customizing a Wordpress tabs widget to match the design in the attached image, I encountered one issue. The challenge lies in keeping the ribbon edges atop the website layout. The progress so far can be viewed in this demo. To display the images, I ...