I’m migrating our test suite from Jest to Vitest. All tests work except for a remaining few which result in this error:
Module /home/d/code/frontend/node_modules/@mui/icons-material/esm/VisibilityOff.js:3 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "@mui/icons-material" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.
As a temporary workaround you can try to inline the package by updating your config:
// vitest.config.js
export default {
test: {
server: {
deps: {
inline: [
"@mui/icons-material"
]
}
}
}
I’ve tried the suggested solution to no avail.
I’ve also tried
resolve: {
alias: [
{ find: '/@src', replacement: './src' },
{
find: /^@mui/icons-material/(.*)/,
replacement: '@mui/icons-material/esm/$1',
},
],
},
I’ve tried
optimizeDeps: {
include: ['@mui/icons-material'],
},
I’ve tried:
resolve: {
alias: {
"@mui/icons-material": "@mui/icons-material/esm",
},
},
I’ve tried changing the rollup options
const baseRollupOptions: RollupOptions = {
external: ['fs/promises', '@mui/icons-material'],
}
I’ve tried
deps: {
optimizer: {
web: {
include: [
'react-cookie',
'redux-signalr',
'@mui/x-charts',
'@babel/runtime',
'd3-color',
'd3-format',
'd3-interpolate',
'd3-scale',
'd3-shape',
'd3-time',
'd3-time-format',
'd3-path',
'd3-array',
'internmap',
'@mui/icons-material',
],
exclude: [
'node_modules/(?!(@mui/icons-material|react-cookie|redux-signalr|@mui/x-charts|@babel/runtime|d3-(color|format|interpolate|scale|shape|time|time-format|path|array)|internmap)/)',
],
},
},
external: [
'node_modules/(?!(react-cookie|redux-signalr|@mui/x-charts|@babel/runtime|d3-(color|format|interpolate|scale|shape|time|time-format|path|array)|internmap)/)',
],
},
No option appears to be working currently.
Curiously the tests that are failing do not seem to even use this particulate mui icon. I also have other tests that run that do use that icon.
I’ve also ensured I cleared the cache before running the test each time (rm -rf node_modules/.vite
)