-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
What version of Bun is running?
1.2.10+db2e7d7f7
What platform is your computer?
MINGW64_NT-10.0-26100 3.4.6.x86_64 x86_64
What steps can reproduce the bug?
I'm using react-router with createBrowserRouter and React.lazy() to implement lazy-loaded routes. However, when running with Bun, the code for lazy-loaded components is not split into separate chunks and is instead bundled and loaded eagerly on initial load.
Steps to reproduce the behavior:
- Define routes using
createBrowserRouterin App.tsx withReact.lazy():import { createBrowserRouter, Outlet, RouterProvider } from 'react-router'; import { Suspense, lazy } from 'react'; const PageComponent = lazy(() => import('./pages/admin')); function LoadingComponent() { return <div>Loading...</div> } function SuspenseWrapper() { return ( <Suspense fallback={<LoadingComponent />}> <Outlet /> </Suspense> ); } const router = createBrowserRouter([ { Component: SuspenseWrapper, children: [ { path: "/admin", Component: PageComponent } ] }, ]); <RouterProvider router={router} />
- Run
bun startwhere in the scriptsNODE_ENV=production bun index.tsx - Both
index.tsxandindex.htmlremain the same as official template Bun + React (TailwindCSS + ShadcnUI)
What is the expected behavior?
This works correctly when running the same code using Node.js or Vite, where lazy-loaded components are split and loaded only when needed.
What do you see instead?
However, when running the app with Bun, as a result, React.lazy() is ineffective — the entire codebase is loaded at once. There is no error message, but the expected component never shows up.
Additional information
No errors are shown in console. The issue seems related to Bun's handling spliting code and load of dynamic imports or React.lazy() behavior. Static imports work fine.