Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

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

@vbilici

Description

@vbilici

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions