Skip to content

React.Lazy import using Fullstack Dev Server & "bun start" not working correctly #19129

@walidsj

Description

@walidsj

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:

  1. Define routes using createBrowserRouter in App.tsx with React.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} />
    
  2. Run bun start where in the scripts NODE_ENV=production bun index.tsx
  3. Both index.tsx and index.html remain 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bake:devhot-reloading dev server for client+server applicationsbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions