Search code examples
reactjslazy-loadingreact-loadable

Lazy loading: react-loadable is failing to load components in other folders


Using Create-react-app, I want to lazy load some of my components, this is working fine as long as the components are in the same folder as my main component (where I define the routes) however as soon as I want to load a component from another folder like

loader: () => import("../containers/HomeAContainer")

it fails to find/import the module. (exact same module will work if I move the file!

I have made a complete example which can be seen here

  • I have also tried to change the route to src/x/x instead of ../x/x but again getting errors.

Solution

  • You are using a wrong path, correct it by using :

    { path: "/c", component: "./containers/HomeAContainer" }