Having trouble getting the default NextJS template to work with TailwindCSS

Sysinfo:
> Windows 11
> Node: v18.16.0
> Next: 13.4.13
> Tested Browser: Firefox, Chrome.

Step to Reproduce


To recreate the issue, I created a NextJS project using the command npx create-next-app tezz with specific options selected:

Would you like to use TypeScript? ... **No** / Yes
Would you like to use ESLint? ... **No** / Yes
Would you like to use Tailwind CSS? ... No / **Yes**
Would you like to use `src/` directory? ... **No** / Yes
Would you like to use App Router? (recommended) ... **No** / Yes
Would you like to customize the default import alias? ... **No** / Yes
Creating a new Next.js app in X:\web\tezz.

Using npm.

Initializing project with template: default-tw

Installing dependencies:
react
react-dom
next
tailwindcss
postcss
autoprefixer

Upon running the project and attempting to compile it for production, I encountered issues with Tailwinds not applying properly. Only the font and some dark background elements were functioning, while other components such as buttons were not displaying correctly. The console displayed the following log message:

> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9aeeffe0e0daaab4abb4aa">[email protected]</a> dev
> next dev

- ready started server on 0.0.0.0:3000, url: http://localhost:3000
- event compiled client and server successfully in 322 ms (18 modules)
- wait compiling...
- event compiled client and server successfully in 288 ms (18 modules)
- wait compiling / (client and server)...
- wait compiling /_error (client and server)...

warn - No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.
warn - https://tailwindcss.com/docs/content-configuration
- event compiled client and server successfully in 3.8s (211 modules)

Although a warning about utility classes was issued, my tailwind.config.js file seemed correct:

/** @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: [],
}

_app.js

import '@/styles/globals.css'

export default function App({ Component, pageProps }) {
  return <Component {...pageProps} />
}

Interestingly, changing the Tailwind version from 3.3.3 to 3.1.8 resolved all the issues, but versions 3.2.0 and above caused CSS problems.

The initial dependencies before the Tailwind version change were:
"dependencies": {
    "autoprefixer": "10.4.14",
    "next": "13.4.13",
    "postcss": "8.4.27",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "tailwindcss": "3.3.3"
  }

Attachment


*) This is the rendered page with tailwind 3.3.3 https://i.sstatic.net/iEUgn.png

*) This is the rendered page with tailwind 3.1.8 https://i.sstatic.net/H79OC.png

I welcome any tips or recommendations as I am relatively inexperienced in frontend development. Thank you!

Resolved by switching back to Tailwind version 3.1.8 as mentioned earlier.

Answer №1

Issue Solved! After some troubleshooting, it seems to be related to my Windows setup. Interestingly, everything is functioning properly on both my Linux environment and Docker.

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 it possible to use the googleapis npm package to make a query to a googleSheet?

I have a huge dataset with thousands of rows and I want to optimize my queries instead of fetching all the data every time. I checked out the Query language but it doesn't quite fit my needs. For authentication, I am using a Service account: const au ...

Error in Javascript: Null Object

I have created an upload page with a PHP script for AJAX, but I'm encountering errors in Firebug. Also, the upload percentage is not being returned properly. Currently, I can only do one upload in Firefox and the script doesn't work in Chrome. H ...

What is the best way to remove all elements in jQuery?

I need to remove the selected element in my demo using jstree. I have consulted the plugin's API at http://www.jstree.com/api/#/?f=deselect_all([supress_event]), but it seems that it does not deselect the item properly. Here are the steps I have follo ...

troubles with dividing string

Recently delving into JavaScript/Angular development and encountering a little roadblock. I am attempting to break up a string of a textarea into an array at the \n character within a controller by utilizing $scope.mytext.split("\n"), however, I ...

Is commenting required? Well, meteor!

I am currently developing a chat application using Meteor and I am facing an issue where I want to require users to type something before sending a message (to prevent spamming by hitting enter multiple times). Unfortunately, I am unsure of how to achieve ...

What methods are most effective for verifying user credentials in a web application using Node.js and AngularJS?

Currently, I am working on a project that involves using Node.js and MySQL for handling user data. I would like to leverage the user information stored in the MySQL database, but I am unsure about the most secure method for implementing user authentication ...

Update the browser URL dynamically without redirecting the page, by utilizing JavaScript after an AJAX call receives a

I am currently endeavoring to find a solution to replace the URL on my page without triggering a reload. My approach involves utilizing an infinite scroll JavaScript plugin. Upon receiving a response from an AJAX call, I intend to update the URL with the n ...

Guide to linking a specific event with JQuery event handlers

I have a Javascript function named Howto that is triggered by a button press: function howto(){ $('#elementtoupdate').ajaxSend(function() { //Code to run }); $('#elementtoupdate').ajaxComplete(function() { //Co ...

Choosing a populated control using JavaScript results in an empty value

Within my ASP.NET applications, I incorporate a server-side HTML select control. <select id="CompanyDropDown" runat="server" style="width:330px"> </select> To populate and pre-select items in this control, I use a JavaScript function triggere ...

designing a presentation with customizable durations for each slide

I am trying to implement a slideshow using the slides.js jquery plugin and I have a specific requirement for the duration of each slide. My goal is to have the first slide, which contains an embedded video, display for 7 seconds, while the subsequent slid ...

The makeSVG function from GoJS is failing to generate the correct HTML SVG object

I have been utilizing the Diagram.makeSVG() method to create an SVG from my diagram. Subsequently, I appended the SVG to a new empty tab using this script (diagram represents my Diagram Object): function print() { var newTab = window.open(), svg ...

Express.js and gridfs-stream are unable to retrieve the error

Imagine an effortless image download server where Express.js takes the request, fetches an image from MongoDB GridFS, and serves it as a response. Everything works fine when the request is valid and the file exists. The issue arises when it fails to catc ...

Animating several elements by toggling their classes

I'm struggling to implement smooth animations on this box. I've tried using 'switchClass' but can't seem to keep everything together. Any help would be greatly appreciated. Here is the code snippet for reference: <script src=" ...

Exploring Angular: How does Number.isNaN handle non-empty strings?

Within my component, there is a dropdown menu that allows users to choose a value. Upon selecting an item from the dropdown, a function called onDropdownChange is triggered. The parameter passed to this function can either be a string ("Please select an op ...

Use jQuery to compare the input values whenever they are modified

I am trying to synchronize the input values of two inputs as they are typed in. The code I have seems to work sometimes, but not consistently. Here is the code snippet: $('#google-querynav').keypress(function() { var text = $(this).val(); ...

Issue with Fancybox and Jquery compatibility

I'm encountering some issues with conflicting Javascripts. One script is responsible for creating a dropdown menu, while another set of scripts enable fancybox functionality. However, having both sets of scripts in the header code results in conflicts ...

I keep encountering the "Port 3000 is in use Error" whenever I try to restart npm run dev

Currently, I am working with nextjs on vscode. To initiate my server in localhost:3000, I use the command npm run dev. Then, to suspend the server, I use the keyboard shortcut ^Z. However, upon trying to restart the server using npm run dev, I encounter th ...

Why isn't the function in my React child component passing its parameters to the parent component's function as expected?

In the parent: const [currentPinPosition, setCurrentPinPosition] = React.useState({ lat: 0 , lng: 0 }); const updateCurrentPinPos = (position) => { console.log(position); setCurrentPinPosition({ lat: position.lat, lng: position.lng }); }; / ...

What is the best way to include a text input as the last option in a Select input form field?

I would like to implement a select input feature where users can choose from predefined options, with the added functionality of including a text input field as the last option for users who prefer to enter their own category. How can I achieve this? Curr ...

Does the Node Schedule library create new processes by spawning or forking them?

Is the node-schedule npm module responsible for spawning/forking a new process, or do we need to handle it ourselves? var cron = require('node-schedule'); var cronExpress="0 * * * *"; cron.scheduleJob(cronExpress, () => { //logger.info(" ...