What are the steps for integrating TailwindCSS with Material UI?

I'm currently working on a project with Next.js and Material UI, but I've run into some difficulties integrating Tailwind CSS with MUI. Despite following this helpful guide, I can't seem to get the classes to apply. If anyone has any tips or suggestions, I would greatly appreciate it!

My Tailwind Configuration:

module.exports = {
  important: "#__next",
  content: ["./pages/**/*.{js,jsx}"],
  theme: {
    extend: {},
  },
  plugins: [],
}

My _app.js:

//import '../styles/globals.css'

//function MyApp({ Component, pageProps }) {
//  return <Component {...pageProps} />
//}

//export default MyApp

import '../styles/edit.css';
import * as React from 'react';
import PropTypes from 'prop-types';
import Head from 'next/head';
import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import { CacheProvider } from '@emotion/react';
import theme from '../config/themeConfig';
import createEmotionCache from '../functions/createEmotionCache';
import Layout from "../components/Layout";
//import '../styles/tailwind.css';


// Client-side cache, shared for the whole session of the user in the browser.
const clientSideEmotionCache = createEmotionCache();

export default function MyApp(props) {
  const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;

  return (
      <Layout>
          <CacheProvider value={emotionCache}>
        <Head>
          <meta name="viewport" content="initial-scale=1, width=device-width" />
        </Head>
        <ThemeProvider theme={theme}>
            <StyledEngineProvider injectFirst>
                {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
                <CssBaseline />
                <Component {...pageProps} />
            </StyledEngineProvider>
        </ThemeProvider>
      </CacheProvider>
      </Layout>
  );
}

MyApp.propTypes = {
  Component: PropTypes.elementType.isRequired,
  emotionCache: PropTypes.object,
  pageProps: PropTypes.object.isRequired,
};

Thank you for your assistance!

Answer №1

The instructions provided in the guide https://mui.com/material-ui/guides/interoperability/#tailwind-css were not followed correctly.

To resolve this issue, make sure to adjust the corePlugins parameter in your tailwind.config.js file to disable the preflight CSS. This is necessary to prevent the preflight CSS from conflicting with MUI styles.

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

Next.js rewrites the original URL and if the response is 404, a custom 404 page will be displayed

I am working on a Next.js app with a rewrites configuration. The destination URL is external. module.exports = { async rewrites() { return [ { source: '/foo/:slug', destination: 'https://example.com/foo/:slug&apos ...

Manipulating CSS content property in React using Material UI

I am trying to set content: "" on my i element: "& i::before": { content: "" }, "& i::after": { content: "" }, However, the style is not being applied and I am seeing an ...

Solving the issue of font awesome override in nextJS

Currently, I am integrating FontAwesome into my NextJS project with Tailwind CSS. Following the official documentation, it instructs to add the given code snippet to _app.tsx file: import { config } from "@fortawesome/fontawesome-svg-core"; impor ...

Sending data to GraphQL queries from an external queries.ts file within a React project

Currently, I am in the process of developing a Next.js application that utilizes GraphQL with ApolloClient to manage API requests. Initially, I had success in setting up a page that functioned correctly and retrieved the appropriate data by passing an ID t ...

Using turbopack with Next.js version 13 results in a "TypeError: Class extends value #" error, whereas no error occurs when using webpack

Recently, my Next.js 13 app running on Turbopack encountered a sudden issue after a few commits. The error message displayed is quite vague - TypeError: Class extends value # in the browser, Uncaught ReferenceError: $RefreshSig$ is not defined in the conso ...

What is the best way to modify the font color of DialogTitle and DialogContent in Material UI within a react.js environment?

Is there a way to customize the font/text color in DialogTitle and DialogContent components using Material UI in react.js? I have successfully changed the background color for the Dialog, but it seems changing the font color for Dialog and DialogContent i ...

In Typescript, it is not possible to assign the type 'any' to a string, but I am attempting to assign a value that is

I'm new to TypeScript and currently learning about how types function in this language. Additionally, I'm utilizing MaterialUI for this particular project. The issue I'm encountering involves attempting to assign an any value to a variable ...

MUI Error: Incorrect prop provided to menu item

I am encountering an issue with a React component that generates a list of elements, each containing a button to open a menu. The problem is that the props being passed to each menu are incorrect; they always reflect the props of the last element in the ...

Customizing the DatePicker with a unique button in material-ui

For my current project, I am utilizing a Datepicker component. I am looking to incorporate a custom information button in the upper right corner of the calendar layout, similar to the example image provided below: https://i.stack.imgur.com/fHMbn.png Unfo ...

Utilizing mp3 files in Webpack 5 with Next.js

After hours of struggling with my current project using [email protected] and webpack v5, I found myself stuck on fixing mp3 loading. Despite trying various solutions from Stack Overflow and GitHub, none seemed to work for me. Type error: Cannot find ...

What is the best method for incorporating ink/ripple effect into an element?

Suppose there is an albums.jsx file containing the following: import ripple from 'material-ui/ripple' In order to apply a ripple effect to an element, you can use the following code: return <div className={ripple}><div> This will ...

Symbol within material UI button

I'm a beginner in React and I'm facing an issue. I have delete icons on buttons, and there are multiple buttons on the front-end. I want only the clicked button to be deleted or disappear, leaving the rest of the buttons untouched and visible on ...

Enable the click functionality for a disabled MI TextField

I'm utilizing a disabled TextField in my project and updating it using React Hooks useState to modify the value property of the TextField. const [employee , setEmployee] = React.useState('') <TextField fullWidth ...

Is it a good idea to relocate the pagination to the top of the DataGrid in MUI

Can someone suggest a solution for moving the default pagination of XGrid above the table? Or do I need to develop my own custom pagination instead of using the built-in feature with XGrid? ...

The function getServerSideProps is not defined in the NextJS environment

I am facing an issue where I need to pass an array called initialPosts into my Home function using getServerSideProps, but the props are showing up as undefined. Despite trying various solutions, none of them seem to work. In getServerSideProps, I have us ...

Unable to set value for React MUI TextField in React Hook Form Controller inside MUI Stepper Dialog

I am facing an issue with my Button that triggers a MUI Dialog to open. Within the Dialog, there is a MUI Stepper as part of my form which has different required and non-required inputs. //Sample Input <Controller name="stateName" co ...

Tips on handling multiple text field validation in material-ui for react?

Currently, I am working on developing a form using Material-UI and React.js where I need to validate two TextField components. My goal is to apply the same error and textHelper props to both TextFields. Below is a snippet of my code for reference. Any sugg ...

Having trouble establishing a connection with mongoose and typescript

When attempting to establish a connection using mongoose, I consistently encounter the errors outlined below. However, if I use MongoClient instead, everything functions as expected. import connectMongo from '../../lib/connectMongo' console.log( ...

Customize Theme for MUI DatePicker Pro

I've been tackling a CSS customization challenge in my MUIX theme for components, but I keep running into frustrating type errors. Let's take the DatePicker Component as an example. Based on the documentation, here's what I should be able to ...

The arrow icon for selecting input in Material Dashboard React is missing

Source Code View Result Why is the arrow icon not visible when viewing the select like this? I am using "@mui/material": "^5.8.6". Can someone please help me with this? <Box sx={{ width: "auto" }}> <FormControl fullWidth> ...