DEV Community

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

Posted on

1

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)

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay