Having issues with TailwindCSS functionality in production environment while using NEXT JS platform

After developing an app for production, I encountered a problem with tailwindcss, postcss, and autoprefixer. While everything worked smoothly during development, once deployed to production, tailwindcss stopped functioning. I attempted to troubleshoot by reinstalling the packages and adjusting paths in the tailwind.config.css file, but nothing seemed to work. I'm at a loss as to what could be causing the issue. Below are my configuration files for tailwindcss and postcss:

Hosting platform: Heroku

tailwindcss.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};

postcss.config.js

module.exports = {
  plugins: {
    tailwindcss: { config: "./tailwind.config.js" },
    autoprefixer: {},
  },
};

Global Styles

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

Answer №1

Give this a shot...

const { join } = require('path');
module.exports = {
  plugins: {
    tailwindcss: {
      config: join(__dirname, 'tailwind.config.js'),
    },
    autoprefixer: {},
  },
};

Do the same for your tailwind.config.js file

 important: true,
 content: [join(__dirname, 'src/**/*.{js,jsx,ts,tsx,vue,html,css}')]

If that doesn't work, consider checking out an alternative source

@config "./tailwindcss-config.js";

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

Answer №2

Answer already provided in this discussion

NextJS: TailwindCSS not working in production

I encountered an issue where the height class of Tailwind CSS worked fine in my development environment, but it didn't work in production.

To resolve this issue, I had to make changes in the tailwind.config.js file. Within the module.exports, I needed to specify all folders containing Tailwind classes like below:

module.exports = {   content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
    "./layouts/**/*.{js,ts,jsx,tsx}",   ],  };

I had created a layout folder and included some layouts with Tailwind CSS there. However, since I did not add the layout folder to the config file, I faced this issue. The problem was resolved after adding the layout folder to the configuration files.

Note that the layout folder should be added at the root directory, outside of the components or pages folders.

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

What is the best way to remove a specific child row in jQuery datatables?

I currently have two static default rows and I would like to add more rows below the existing ones without deleting the parent rows. However, I am unsure of how to delete child rows without affecting the parent rows. My parent rows consist of the defaul ...

Transforming jQuery into React - implementing addClass and removeClass methods without using toggle

I'm working on creating two grid resize buttons for a gallery list. One is for a smaller grid (.museum-grid) and the other for a larger grid (.large-grid). Here's what I want to happen when I click #museum-grid-btn: Add class .museu ...

What are the steps to troubleshoot generateStaticParams in PhpStorm for Next.js development?

While I can successfully add breakpoints to my Page method, I am unable to do so within the generateStaticParams function. Interestingly, when I insert a console.log statement, I can observe that it gets executed both during development and build time. I ...

Excessive vertical space is utilized by the vertical images in the CSS grid image gallery

My responsive CSS grid gallery is experiencing issues with vertical images disrupting the layout, as they appear at full size instead of remaining square like the others. How can I fix this problem? Thank you! Below is the code snippet: <div id=" ...

Is it possible for an ul to be displayed beneath a white section within an li

I am working on a JQuery carousel that is displaying correctly, but I want to make a small adjustment to the content: <li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal" style="float: left; list-style: none ...

Animating a div using a changing scope variable in AngularJS

As a newcomer to Angular, I am looking to add animation to a div element using ng-click within an ng-repeat loop. Here is what I have attempted: app.js var app = angular.module( 'app', [] ); app.controller('appController', function($ ...

I am trying to figure out how to receive emails from my Vercel deployed Next.js project using Resend, but I am not seeing any logs. Can

In my next.js project, I am using Resend for email sending in the contact form. Despite filling out and submitting the form, I am not receiving any emails or seeing any log indicating success or failure in Resend. Strangely, I do see a successful message ...

Are there drawbacks to utilizing large integer values as array indexes?

Simply put. We are discussing javascript here. I am wondering about the potential performance drawbacks, memory issues, and so on when using high value integers as array indexes instead of low value ones. Some programming languages allocate enough memory ...

Tips for effectively utilizing the page-break property within CSS

I am faced with an issue on my HTML page where multiple angular material cards are being displayed: ... <mat-card class="mat-card-98"> <mat-card-header> <mat-card-title>THIS IS MY TITLE</mat-card-title> < ...

"Unearthing a skeleton within the client component while the server action unfolds in next

One of the challenges I'm encountering involves a client component that initiates a server action. The server action returns a result, which triggers an update in the UI. Take a look at the code snippet provided below for reference export default func ...

The fullscreen revolution slider in Wordpress is displaying a small white space below it

Check out my website at: . As I reduce the browser width, a blank space appears below the top revolution slider. I'm struggling to get rid of it. Here's what I've tried so far: .boxedWrap .fullScreenSlider {height: 100%;} .boxedWrap .fu ...

bespoke design picture holder

Is it possible to create a custom-shaped image container without using <div />? I encounter an issue when trying to add corners on top of the #content-box as shown in this screenshot: . The corner images only cover half of the block element, with th ...

Utilizing a custom font to emphasize the extended phrase in the following sentence

I've been trying to use word-wrap to break long words into the next line, but unfortunately it's not working as expected. You can view my JsFiddle code for reference. The divs on my page are generated dynamically, and here is an overview of what ...

The function res.revalidate() is not a valid method within the NextResponse module of Nextjs when trying to implement on-demand

Currently, NextResponse does not support res.revalidate('/'). I am working with version v12.2.5, although this feature has been available since v12.2.0. My goal is to implement on-demand ISR using TypeScript. Learn more about on-demand Increment ...

Display images horizontally using a foreach loop

After seeking help with this script previously, I am returning because it is still displaying vertically. What I am aiming for is to have three photos displayed per line, resulting in two rows of 3 images each, totaling 6 images. <div class="4u"> ...

Encountering errors when attempting to preview a Strapi/Next.js starter after a fresh installation

Currently, I have a fresh installation of the strapi-starter-next-corporate starter app. On attempting to view a preview of an unpublished "secret" page, I encountered the following error: [develop:frontend] error - ReferenceError: locale is not defined [d ...

Arrange the items in AngularJS using ng-repeat from horizontal to vertical orientation

I am currently using ng-repeat on floated left <li> elements, resulting in a horizontal list. Is there a way to repeat the same items vertically as shown below? from: Item1 Item2 Item3 Item4 Item5 Item6 Item7 Item8 Item9 Item10 to: Item1 ...

Limiting text based on the space it occupies

Is it feasible to restrict the number of characters allowed in an input field based on the space they occupy? For instance, W's and M's require enough space for 34 of them. https://i.sstatic.net/xQW5p.png However, regular sentences of the same ...

Show a concealed vertical menu on mobile using CSS

I successfully implemented a drop-up footer on my website: $('#drop-up-open').click(function() { $('#drop-up #drop-upDashboard').slideToggle({ direction: "up" }, 300); $(this).toggleClass('drop-upClose'); }); // e ...

Enhancing user experience with scroll snapping within nested components/elements

https://i.sstatic.net/PzNmP.gif Looking at the gif, you can see a large scrollable container with various main blocks ('Attack', 'Release', etc.) housed within it. Each main block contains one or multiple columns (such as 'Attack ...