Next.js Project Encounters Compilation Error Due to Tailwind CSS Custom Class

I am currently working on a Next.js project and incorporating Tailwind CSS. Unfortunately, I have come across a compilation error that I am struggling to resolve. The error specifically pertains to a custom utility class that I defined in my theme.css file. Here is the error message I am receiving:

Failed to compile

./styles/theme.css:7:9
Syntax error: D:\Developer\Projects\Nextjs13\nextapp\styles\theme.css The `bg-light-850` class does not exist. If `bg-light-850` is a custom class, make sure it is defined within a `@layer` directive.

  5 | @layer utilities {
  6 |     .background-light850_dark100 {
>> 7 |         @apply bg-light-850 dark:bg-dark-100;
    |         ^
  8 |     }
  9 |     .background-light900_dark200 {

Within my theme.css file, I have the following code:

@layer utilities {
    .background-light850_dark100 {
        @apply bg-light-850 dark:bg-dark-100;
    }
    // ... other classes ...
}

Furthermore, my tailwind.config.ts file includes the following:

// ... other config settings ...

extend: {
  colors: {
    // ... other colors ...
    light: {
      900: '#FFFFFF',
      800: '#F4F6F8',
      850: '#FDFDFD',
      // ... other light colors ...
    },
    // ... other color settings ...
  },
  // ... other extended theme settings ...
}

// ... rest of the configuration ...

Although the color light-850 is defined in my Tailwind configuration, the compiler is not recognizing it. I have attempted to clear the Next.js cache and rebuild the project, but the error persists.

If anyone could provide insight into why this error is happening and how to resolve it, I would greatly appreciate it.

Thank you all for your help!

Tried to rebuild, clear cache, and seek assistance from copilot.

Answer №1

Upon delving deeper into the matter, I unearthed that the root cause was related to the content array specified in my tailwind.config.ts file. This array essentially guides Tailwind on where to find class names within the project structure. I had a mix of file types (.js, .ts, .jsx, .tsx, .mdx) listed in the array, but unfortunately, the theme.css file containing the custom class was not being processed correctly.

To tackle this issue, I ensured that the theme.css file was situated in one of the directories mentioned in the content array. Furthermore, I double-checked the syntax within the theme.css file, paying close attention to the @apply directive and CSS comment syntax.

In addition to these steps, I cleared the project cache and initiated a rebuild, as this is crucial for any adjustments made to the Tailwind configuration to take effect. This proactive approach successfully rectified the error, allowing the custom class to be recognized seamlessly.

It is imperative to maintain consistency in the file types included in the Tailwind content array and to meticulously verify the positioning and syntax of custom CSS files within your project.

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

Is Babel necessary for a Node.js server application, and what are the benefits of using it?

My fondness for ES6 syntax and its new object-oriented style makes coding much easier for me. However, as a newcomer to JavaScript, I am curious about the advantages and disadvantages of using Babel in terms of performance, maintenance, readability, and ...

Caution: Using the useAutoComplete feature with Next.js Material UI may trigger a warning about spreading a props object containing a "key" prop into JSX

I am currently working on implementing the customized hook from the mui documentation: <Root> <div {...getRootProps()}> <Label {...getInputLabelProps()}>Tags</Label> <InputWrapper ref={setAnchorEl} className ...

Creating a function in typescript that returns a type based on the input parameter

type A = { aa: string; bb: number; }; type G = { <T extends keyof A>(a: T): A[T]; <T1 extends keyof A, T2 extends keyof A>(a: T1, b: T2): [A[T1], A[T2]]; // ... }; const g = {} as G; const x = g('aa'); //string const y = g ...

A guide on handling and presenting an array of objects using AngularJS

I am currently working on a project where I have a large array of objects that need to be filtered, processed, and then displayed to the user. The application is built using node-webkit and I am using AngularJS and jQuery for routing, DOM manipulation, and ...

Duplicating an array retrieved through a jQuery ajax request

Currently, I am encountering an issue while attempting to duplicate a JSON array within this specific JavaScript function: var test = new array(); function showUser(user, pass, remember) { $.getJSON("login.php", { username : user, password : pass, che ...

JavaScript library unsuccessful in transferring data to PHP script

I am facing an issue while trying to transfer variables from javascript to a php file for execution. The problem is that the php file is not being called or executed, even though I have confirmed that it works properly when tested individually. $(function ...

Exploring the use of barcodes with node.js

Having some issues with generating a barcode using a barcode module from NPMJS called npm i barcode. I am getting an error message res is not defined even after following the instructions. Can someone please guide me in the right direction? Here is my code ...

Accessing the data from an HTML5 slider using JQuery

Having some difficulty fetching a value from an HTML5 slider using JQuery. Here is my code snippet: JQuery Code: // Getting the value from slider one $("#submit").on("click", function(evt) { var sliderValue = $('#slider01').attr('value ...

Is it possible to view the code within the .js files located in the api directory of NextJS using web browsers?

Is it possible to view the code of ".js files" in the "api folder" of NextJS using browsers? I came across a post on Stack Overflow where someone asked if Next.js API is back-end, and one of the answers stated: The back-end or server-side of Next.js res ...

Tips on detecting a collision between a cube mesh and the boundaries of a browser using ThreeJS

I'm a beginner in 3D games and ThreeJS. In the image above, my Mesh is located at the left boundary of the browser with a position of -1035 instead of 0. This leads me to question what exactly is the relationship between mesh.position.x in ThreeJS and ...

Make sure the static variable is set up prior to injecting the provider

In our Angular6 application, we utilize a globalcontextServiceFactory to initialize the application before rendering views. This process involves subscribing to get configuration from a back-end endpoint and then using forkJoin to retrieve environment app ...

Ubuntu is experiencing a DNS problem. While the URL request works perfectly on MacOSX, it is unsuccessful on Ubuntu

A custom nodeJS script has been developed to utilize the require('request').post() method. The script executes successfully on MacOSX (Travis), however encounters issues on Ubuntu (Travis). To troubleshoot, experimentation with NodeJS 'https ...

Prevent JavaScript from sending a POST request to a specific URL

Currently facing Cross Site Scripting (XSS) vulnerabilities in a web application, I am curious if there are security measures equivalent to Content-Security-Policy: frame-ancestors and X-Frame-Options for JavaScript. My objective is to restrict the abilit ...

Using jQuery to dynamically populate select options based on JSON data

I have been testing and searching for a solution to my issue, but it still doesn't work. Any help would be greatly appreciated. I have three select options implemented in PHP like this: <div class="control-group" id="merkPrinter"> <label cl ...

A guide on how to efficiently update and submit a reactive form with a single click of the submit button in Angular

Currently, I have a view component setup where clicking the edit button directs me to the register component for form updates using patchvalue. The issue that I am facing is that when I update and register the form using the same button, it creates anothe ...

Incorporate create-react-app with Express

Issue - I am encountering a problem where I do not receive any response from Postman when trying to access localhost:9000. Instead of getting the expected user JSON data back, I am seeing the following output: <body> <noscript>You need to ...

Implementing a dialog box pop-up from a separate React file

My journey with React is just beginning, so forgive me if this question seems basic. I have a delete icon in one of my files, and when it's clicked, I want to display a confirmation dialog box. I found an example on the official Material-UI website: h ...

Using React JS to send an object as an argument to an action function

How do I pass the "fields" object to the action "createPost" after creating it with validation in a form? Do I need to use "props" or could it be related to the dispatcher line? import React, { Component } from 'react'; import Header from ' ...

Guide to importing images (.svg, .png) into a React component

I'm currently facing an issue trying to upload an image file in one of my React components using webpack. My project is already set up with web pack. Below is the code snippet for the component: import Diamond from '../../assets/linux_logo.jpg& ...

What could be causing my array to be misconverted into JSONP data?

let defaultPosts = new Array([]); defaultPosts[0] = "first post"; defaultPosts[1] = "second post"; defaultPosts[2] = "third post"; The array in the console is showing ["first post", "second post", "third post"]; let jsonString = JSON.stringi ...