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)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more