Error in Taiwlind CSS: Styles are not loading in production environment but are working fine in development environment. This issue is encountered while using Next.js in

After reading various blog posts online, I put together this code snippet. The confusion arises from blogs using autoprefixer while others use postcss-preset-env.

In my setup, I have added tailwindcss as a development dependency and properly imported the styles in pages/_app.tsx. Here are the relevant files:

package.json

"dependencies": {
    "@mapbox/rehype-prism": "^0.5.0",
    "@mdx-js/react": "^1.6.19",
    "@types/nprogress": "^0.2.0",
    ...
},
...

tailwind.config.js

const defaultTheme = require('tailwindcss/defaultTheme')

module.exports = {
    future: {
        removeDeprecatedGapUtilities: true,
        purgeLayersByDefault: true,
    },
    purge: {
        ...
    },
    theme: {
        extend: {
            colors: {
                'accent-1': '#333',
            },
            fontFamily: {
                sans: ['Inter var', ...defaultTheme.fontFamily.sans],
            },
        },
    },
    variants: {},
    plugins: [
        function ({ addBase, addComponents, theme }) {
            ...
        },
    ],
}

postcss.config.js

module.exports = {
    plugins: [
        'tailwindcss',
        'postcss-flexbugs-fixes',
        process.env.NODE_ENV === 'production'
            ? [
                    '@fullhuman/postcss-purgecss',
                    ...
              ]
            : undefined,
        ...
      ],
}

Despite following what seems to be the correct steps, I am encountering errors. Can someone point out where I might be going wrong?

Answer №1

Successfully solved the issue.

I decided to eliminate the entire section below from postcss.config.js:

process.env.NODE_ENV === 'production'
            ? [
                    '@mypackage/postcss-purgecss',
                    {
                        content: ['./pages/**/*.{js,jsx,ts,tsx}', './components/**/*.{js,jsx,ts,tsx}'],
                        defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
                    },
              ]
            : undefined,

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 method for accessing OpenWeatherMap details via JSON?

I am facing a challenge in JavaScript as I attempt to create a program that fetches weather information from OpenWeatherMap using JSON. My experience with JSON is limited, but I believe I have a grasp of the underlying concepts. Despite this, when I trigge ...

Changes in props do not automatically update children via Ref

I'm working on a React component that needs to update whenever the width changes: import { useRef, useEffect, useState } from "react"; function Child({ containerWidth }) { console.log("CHILD", containerWidth); return <div&g ...

Which Browser (or version) is the Only One That Cannot Manipulate Flash Objects?

In my attempts to modify Flash Objects / Embeds using Javascript, I've found that it works in all browsers except for IE. This has led me to consider abandoning IE altogether for this application, unless there are other older or less used browsers tha ...

Prevent child element from being rotated along with parent element

I am facing an issue with two div elements: a parent element that is rotated and a child element that I want to remain unaffected by the rotation of its parent. To tackle this problem, I tried rotating the child element in the opposite direction of the pa ...

Using JavaScript to skip duplicate rows in an HTML table based on group

My current task involves fetching multiple data from a database using AJAX and PHP. Once I retrieve the data successfully, I need to group the results in a specific format like the images shown below, including having a textarea field for each group. Here ...

Is it possible to incorporate a YouTube video into a webpage without displaying any external links to YouTube above the video player?

Looking for a solution to embed a YouTube video on my webpage without the link appearing when hovering over it and without the suggested videos at the end. Just the option to replay the video without the distraction of related videos. ...

Whispering form using onblur and onfocus

Seeking assistance with echoing a form that includes multiple input fields. Specifically, I am attempting to utilize onblur and onfocus (refer to the conditions outlined in the code). However, I am encountering an issue where the Javascript function does ...

What could be causing the child of an ES6 imported object to return as undefined?

Here is the code snippet I am working with: import * as _routes from '../../routes' console.log('parent:', _routes) console.log('child:', _routes.breadcrumb) This code produces the following output: https://i.stack.imgur.co ...

What could be the reason behind the issue of my HTML draggable feature not functioning properly on touch

I've set up a draggable div with headers and p tags, but I'm encountering an issue when trying to run it on a touch screen. The div tag isn't draggable in this scenario. Can anyone suggest the best solution for making this page touch screen ...

Can you explain the process of NuxtJS css extraction for creating static websites?

I am currently working on creating a static website using my minimal code with Nuxt. This code includes integration of the tailwindcss toolkit and vue2-leaflet. When I run nuxt generate I end up with two CSS files - one for the tailwindcss styles and an ...

challenges surrounding the use of getElementByTagName

Within my webpage, I have implemented two select elements, both containing multiple options. However, I am facing an issue where I can only access the options from the first select box using getElementByTagName("options"), and unable to retrieve the option ...

Select a user at random from the reactions in the message

Is there a way to select a user at random from message reactions on Discord? Despite going through all the documentation, I'm still unsure about how to do this. ...

Difficulty encountered with changing font color on CSS

I'm having trouble fixing the text color, it's currently white and blending in with the background. I've set the color to #1a6eb6 for both the TEXT element and the submenu list items, but it's not working. Can someone assist me with thi ...

Merging sort and uniq functionalities to create a single function in JavaScript

I've been working with the sortBy and uniqBy functions, but I find myself iterating over the array twice when using the combined sortUniqBy. If you want to check out the code, feel free to click on this link to the codesandbox. Here's a snippet o ...

working with html data in a bootstrap modal using javascript

Utilizing an id, I pass data to a bootstrap modal and link that id with stored data. $("#fruit").html($(this).data("fruit")); In addition, I am appending data to the bootstrap modal $('#mymodal').find('.modal-body').append('< ...

Using :nth-child on elements with the same class name does not produce the desired result

I attempted to utilize the :nth-child selector to target the first, third, and fifth elements with the class name "personal", but it did not work as expected. Is there an alternative method to specifically select these elements sharing the same class? I ha ...

I'm currently working on implementing custom hover animations for the navigation items in my React application, using Bootstrap nav. However, I'm facing an issue where

I'm attempting to implement a custom hover effect on my navigation items using external CSS. However, when I import it into my Navbar, the Bootstrap styles are not being overridden and the effect is not visible. Additionally, when the Navbar collapses ...

Unable to interact with the page while executing printing functionality in

component: <div class="container" id="customComponent1"> New Content </div> <div class="container" id="customComponent2"> different content </div> ...

Divergent behavior of jQuery AJAX when used with a standard form versus when called in a popup within a div

Why does the jQuery AJAX work perfectly when submitting a form using the normal method, but not when submitting the same form within a popup? Below is the code for reference. Form submission script: $("#submit").click(function (e) { /* $('form&a ...

The DIV element is not visible on the page, and the z-index property does not seem to be working

I am attempting to replicate the diagonal stripe layout using CSS, similar to the design shown here: Here is my codepen: http://codepen.io/Chiz/pen/zvWRNW Although my layout appears acceptable, the issue lies in the "div class="blacktop" not displaying. ...