webpack code splitting with require.ensure doesn't work on the server side #1390

Closed
opened 2025-08-09 17:19:58 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @vbilici on 9/13/2016

Hi,
I am trying to implement a lazy component loading system over the react-redux example. I built a lazy loading component which works perfectly fine on browser side. But if i try to load the route directly from server, node.js throws an error:

An unhandled exception occurred while processing the request. Exception: Call to Node module failed with error: Error: Cannot find module './1.webpack-output.js' at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Function.requireEnsure as e
at Object.getComponent (C:\Dev\tests\frontend-net-core\ClientApp\boot-server.js:230:34)
at getComponentsForRoute (C:\Dev\tests\frontend-net-core\node_modules\react-router\lib\getComponents.js:29:16)
at C:\Dev\tests\frontend-net-core\node_modules\react-router\lib\getComponents.js:41:5
at C:\Dev\tests\frontend-net-core\node_modules\react-router\lib\AsyncUtils.js:84:5
at Array.forEach (native)
MoveNext

and here is my router config:
`const rootRoute = {
component: Layout,

childRoutes: [
    {
        path: '/',
        component:   Home
    },
    {
        path: '/counter',
        component:  Counter 
    },
    {
        path: '/fetchdata',
        component: FetchData ,
        childRoutes: [
            {
                path: ':startDateIndex'
            }
        ]
    },
    {
        path: '/lazy',
        getComponent(nextState, cb) {
            require.ensure([],
                (require) => {
                    cb(null, require('./components/lazy').default);
                });
        }
    }
]

}`

I think this is a bug with the aspnet-webpack module but I couldn't be sure about it.

*Originally created by @vbilici on 9/13/2016* Hi, I am trying to implement a lazy component loading system over the react-redux example. I built a lazy loading component which works perfectly fine on browser side. But if i try to load the route directly from server, node.js throws an error: > An unhandled exception occurred while processing the request. Exception: Call to Node module failed with error: Error: Cannot find module './1.webpack-output.js' at Function.Module._resolveFilename (module.js:325:15) > at Function.Module._load (module.js:276:25) > at Module.require (module.js:353:17) > at require (internal/module.js:12:17) > at Function.requireEnsure [as e](C:Devtestsfrontend-net-coreClientAppboot-server.js:40:25) > at Object.getComponent (C:\Dev\tests\frontend-net-core\ClientApp\boot-server.js:230:34) > at getComponentsForRoute (C:\Dev\tests\frontend-net-core\node_modules\react-router\lib\getComponents.js:29:16) > at C:\Dev\tests\frontend-net-core\node_modules\react-router\lib\getComponents.js:41:5 > at C:\Dev\tests\frontend-net-core\node_modules\react-router\lib\AsyncUtils.js:84:5 > at Array.forEach (native) > MoveNext and here is my router config: `const rootRoute = { component: Layout, ``` childRoutes: [ { path: '/', component: Home }, { path: '/counter', component: Counter }, { path: '/fetchdata', component: FetchData , childRoutes: [ { path: ':startDateIndex' } ] }, { path: '/lazy', getComponent(nextState, cb) { require.ensure([], (require) => { cb(null, require('./components/lazy').default); }); } } ] ``` }` I think this is a bug with the aspnet-webpack module but I couldn't be sure about it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1390
No description provided.