Repository navigation
next/jest doesn't use optimizePackageImports #100704
Replies: 1 comment
|
Confirmed — this is a real gap, not a config mistake on your side. Workarounds until this is fixed: |
|
Confirmed — this is a real gap, not a config mistake on your side. Workarounds until this is fixed: |
Uh oh!
There was an error while loading. Please reload this page.
Goals
Non-Goals
Background
Next optimizes barrel imports by default for a list of packages (MUI, lodash-es, date-fns, lucide-react and more). That works in next dev and next build, but not when you run tests through next/jest, so every test file loads the whole package.
Small repro: https://github.com/jeltehomminga/next-jest-barrel-repro
With import { Button } from '@mui/material', Jest loads 567 MUI files. With import Button from '@mui/material/Button', it loads 81. Over 50 test files that's about 2.0s vs 1.5s.
You can work around it with modularizeImports, but that breaks for things like ThemeProvider and createTheme, which don't have their own import path.
Proposal
I'm not sure what the best fix is. In the app this goes through a webpack loader, so I guess it can't just be passed to Jest. Maybe next/jest could reuse the same barrel step somehow
All reactions