Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DefaultTheme in Material-UI causes `Invalid module name in augmentation` error

As described in the migration docs (v4 to v5) I've added this to my theme:

import { createTheme, Theme } from '@mui/material/styles'
import { grey } from '@mui/material/colors'

declare module '@mui/styles/defaultTheme' { // <-- ts error
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
  interface DefaultTheme extends Theme {}
}

const { palette } = createTheme()
const { augmentColor } = palette

// Create a theme instance.
export const theme: Theme = createTheme({
  palette: {
    neutral: augmentColor({ color: { main: grey[400] } }),
  }
})

But I get the ts error Invalid module name in augmentation, module '@mui/styles/defaultTheme' cannot be found.ts(2664)

What am I doing wrong?

like image 294
user3142695 Avatar asked Feb 23 '26 15:02

user3142695


1 Answers

I don't know why, but importing the module for side-effects fix it:

import { Theme } from "@mui/material/styles";
import "@mui/styles";

declare module "@mui/styles/defaultTheme" {
  // eslint-disable-next-line @typescript-eslint/no-empty-interface (remove this line if you don't have the rule enabled)
  interface DefaultTheme extends Theme {}
}
like image 100
NearHuscarl Avatar answered Feb 26 '26 04:02

NearHuscarl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!