DEV Community

Cover image for Fresh CRA + React.lazy + code splitting: why isn't it working as should?
Denis Anikin
Denis Anikin

Posted on

Fresh CRA + React.lazy + code splitting: why isn't it working as should?

If you ever come across this topic and find yourself stuck with «why my bundle is not splitting up for chunks, but I'm doing everything as said» after reading documentation, please: check that the component used inside classic construction

React.lazy(() => import('MyFancyApp'))
Enter fullscreen mode Exit fullscreen mode

is not imported anywhere else in your application!
Yeah, that easy, but not that easy if your start debugging right now and searching for information online. The whole internet is flooded with identical articles and standard recipes.

In our team's case, it was index.tsx files with helper imports. Like this:

# index.tsx
export * from "./MyFancyApp.tsx"
Enter fullscreen mode Exit fullscreen mode

Remove or replace these imports with lazy implementation and splitting starts working as it should.

Top comments (0)