{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/JavaScriptServices/issues/306","repository_url":"https://api.github.com/repos/aspnet/JavaScriptServices","labels_url":"https://api.github.com/repos/aspnet/JavaScriptServices/issues/306/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/JavaScriptServices/issues/306/comments","events_url":"https://api.github.com/repos/aspnet/JavaScriptServices/issues/306/events","html_url":"https://github.com/aspnet/JavaScriptServices/issues/306","id":176727287,"number":306,"title":"webpack code splitting with require.ensure doesn't work on the server side","user":{"login":"vbilici","id":2687297,"avatar_url":"https://avatars.githubusercontent.com/u/2687297?v=3","gravatar_id":"","url":"https://api.github.com/users/vbilici","html_url":"https://github.com/vbilici","followers_url":"https://api.github.com/users/vbilici/followers","following_url":"https://api.github.com/users/vbilici/following{/other_user}","gists_url":"https://api.github.com/users/vbilici/gists{/gist_id}","starred_url":"https://api.github.com/users/vbilici/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vbilici/subscriptions","organizations_url":"https://api.github.com/users/vbilici/orgs","repos_url":"https://api.github.com/users/vbilici/repos","events_url":"https://api.github.com/users/vbilici/events{/privacy}","received_events_url":"https://api.github.com/users/vbilici/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-13T19:22:10Z","updated_at":"2016-09-15T17:46:10Z","closed_at":"2016-09-14T10:44:59Z","body":"Hi,\r\nI 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:\r\n\r\n> 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)\r\nat Function.Module._load (module.js:276:25)\r\nat Module.require (module.js:353:17)\r\nat require (internal/module.js:12:17)\r\nat Function.requireEnsure [as e] (C:\\Dev\\tests\\frontend-net-core\\ClientApp\\boot-server.js:40:25)\r\nat Object.getComponent (C:\\Dev\\tests\\frontend-net-core\\ClientApp\\boot-server.js:230:34)\r\nat getComponentsForRoute (C:\\Dev\\tests\\frontend-net-core\\node_modules\\react-router\\lib\\getComponents.js:29:16)\r\nat C:\\Dev\\tests\\frontend-net-core\\node_modules\\react-router\\lib\\getComponents.js:41:5\r\nat C:\\Dev\\tests\\frontend-net-core\\node_modules\\react-router\\lib\\AsyncUtils.js:84:5\r\nat Array.forEach (native)\r\nMoveNext\r\n\r\nand here is my router config:\r\n`const rootRoute = {\r\n    component: Layout,\r\n\r\n    childRoutes: [\r\n        {\r\n            path: '/',\r\n            component:   Home\r\n        },\r\n        {\r\n            path: '/counter',\r\n            component:  Counter \r\n        },\r\n        {\r\n            path: '/fetchdata',\r\n            component: FetchData ,\r\n            childRoutes: [\r\n                {\r\n                    path: ':startDateIndex'\r\n                }\r\n            ]\r\n        },\r\n        {\r\n            path: '/lazy',\r\n            getComponent(nextState, cb) {\r\n                require.ensure([],\r\n                    (require) => {\r\n                        cb(null, require('./components/lazy').default);\r\n                    });\r\n            }\r\n        }\r\n    ]\r\n}`\r\n\r\nI think this is a bug with the aspnet-webpack module but I couldn't be sure about it.\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/JavaScriptServices/issues/comments/247399613","html_url":"https://github.com/aspnet/JavaScriptServices/issues/306#issuecomment-247399613","issue_url":"https://api.github.com/repos/aspnet/JavaScriptServices/issues/306","id":247399613,"user":{"login":"vbilici","id":2687297,"avatar_url":"https://avatars.githubusercontent.com/u/2687297?v=3","gravatar_id":"","url":"https://api.github.com/users/vbilici","html_url":"https://github.com/vbilici","followers_url":"https://api.github.com/users/vbilici/followers","following_url":"https://api.github.com/users/vbilici/following{/other_user}","gists_url":"https://api.github.com/users/vbilici/gists{/gist_id}","starred_url":"https://api.github.com/users/vbilici/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vbilici/subscriptions","organizations_url":"https://api.github.com/users/vbilici/orgs","repos_url":"https://api.github.com/users/vbilici/repos","events_url":"https://api.github.com/users/vbilici/events{/privacy}","received_events_url":"https://api.github.com/users/vbilici/received_events","type":"User","site_admin":false},"created_at":"2016-09-15T17:46:10Z","updated_at":"2016-09-15T17:46:10Z","body":"Ok, I found another solution.\r\nI split prerender config file from the default one and added define plugin:\r\n\r\nwebpack.config.ssr.js\r\n```\r\n    ...\r\n    plugins: [\r\n        ExtractCss,\r\n        new ExternalsPlugin({ type: 'commonjs', include: /node_modules/ }),\r\n        new webpack.DefinePlugin({\r\n            __DEV__: isDevelopment,\r\n            __WEBPACK_SERVER__: true\r\n        })\r\n    ],\r\n    ...\r\n```\r\n\r\nand in the code:\r\nclientApp/routes.js\r\n```\r\n        ...\r\n        {\r\n            path: '/lazy',\r\n            getComponent(nextState, cb) {\r\n                debugger;\r\n                if (__WEBPACK_SERVER__) {\r\n                    cb(null, require('./componentsLazy/lazy').default);\r\n                } else {\r\n                    require.ensure([],\r\n                        (require) => {\r\n                            cb(null, require('./componentsLazy/lazy').default);\r\n\r\n                        });\r\n                }\r\n\r\n            }\r\n        }\r\n``` \r\n\r\nViews/Home/index.chtml:\r\n```\r\n<div id=\"react-app\" asp-prerender-module=\"ClientApp/boot-server\"\r\n     asp-prerender-webpack-config=\"webpack.config.ssr.js\"\r\n     \">\r\n    Loading...\r\n</div>\r\n```\r\nTested on development mode, production mode  and published to IIS server.\r\n\r\nBut if you have a better solution please let me know.\r\nThanks."}}
{"actor":{"display_login":"vbilici"}}