Migrating from MUI v4 to v5: Can't declare module "@mui/styles/defaultTheme"

Viewed 265

I'm attempting to follow Material-U's instructions to migrate from MUI v4 to MUI v5, but ran into the troubleshooting issue Property "palette", "spacing" does not exist on type 'DefaultTheme.'

I'm following the troubleshooting suggestions listed here, and added the following code to my theme.tsx file:

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

declare module '@mui/styles/defaultTheme' {
  interface DefaultTheme extends Theme {}
}

but get the following error on the line declare module "@mui/styles/defaultTheme in theme.tsx:

Invalid module name in augmentation, module '@mui/styles/defaultTheme' cannot be found.ts(2664)
module "@mui/styles/defaultTheme"

That code snippet does not throw the same error if I include it in App.tsx, but including it in App.tsx does not silence the Property "palette","spacing" does not exist on type 'DefaultTheme error.

How can I either a) avoid the invalid module name in augmentation error in theme.tsx or b) overcome the does not exist on type DefaultTheme error in a different way?

0 Answers
Related