Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,64 @@
}
```

## Configuration with Vite and Vitest

If you are using Vite with Vitest for testing, you may encounter issues with MUI v7+ when using styled-components. This is due to ESM/CJS compatibility issues with styled-components.

Check warning on line 49 in docs/data/material/integrations/styled-components/styled-components.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [MUI.NoCompanyName] We avoid referencing the company name 'MUI v7'. Instead you can reference a product or the team. Raw Output: {"message": "[MUI.NoCompanyName] We avoid referencing the company name 'MUI v7'. Instead you can reference a product or the team.", "location": {"path": "docs/data/material/integrations/styled-components/styled-components.md", "range": {"start": {"line": 49, "column": 78}}}, "severity": "WARNING"}

To resolve this, add the following configuration to your `vite.config.ts`:

### Option 1: Using fallbackCJS (simpler, but slower)
```ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
test: {
environment: 'jsdom',
globals: true,
server: {
deps: {
fallbackCJS: true,
},
},
},
plugins: [react()],
});
```

### Option 2: Using inline dependencies (faster, recommended)
```ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
test: {
environment: 'jsdom',
globals: true,
server: {
deps: {
inline: [
'@mui/material',
'@mui/system',
'@mui/styled-engine',
'@mui/icons-material',
// Add other MUI packages you're using, such as:
// '@mui/x-date-pickers',
// '@mui/x-data-grid',
],
},
},
},
plugins: [react()],
});
```

The `inline` option provides better performance and is the recommended approach for most projects.

:::info
You must also override `styled-engine` in your `package.json` when working with Vite + Vitest, otherwise Vitest will resolve `@mui/styled-engine` instead of `@mui/styled-engine-sc`. See the [installation instructions](#installation) above for details.

Check warning on line 102 in docs/data/material/integrations/styled-components/styled-components.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.Will] Avoid using 'will'. Raw Output: {"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "docs/data/material/integrations/styled-components/styled-components.md", "range": {"start": {"line": 102, "column": 113}}}, "severity": "WARNING"}
:::

### With npm

Because package resolutions aren't available with npm, you must update your bundler's config to add this alias.
Expand Down
Loading