webpack-hot-server-middleware: Dynamically / lazily loaded chunks throw an error

Hello, I’m trying to implement this with Angular2. Everything seems to be working fine client side, but SSR is not working with “lazy-loaded” chunks Error: Cannot find module './0.server.js'.

I tried using LimitChunkCountPlugin but the rabbit hole seemed to be deeper. Now I looked at the MemoryFileSystem and the file is definitely there.

Eventually I got it to work, but I had to run a build before running the server, which is weird, it seems like it needs the disk files to be there before starting, but it still uses the memory files. I know it doesn’t use disk files because deleting their content doesn’t change the outcome, and changes to /src files (i.e. rebuilding) doesn’t change them, however, if I delete the file from disk, it bugs out again. 😕

Here’s the branch I’m working on https://github.com/S-Intelligent-Technologies/sit-ngx-starter/tree/fm-better-hmr

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 18 (1 by maintainers)

Most upvoted comments

I think I get a similar error when I import my files dynamically It works fine with a static import: import ExploreView from './containers/ExploreView'

but with a dynamic import:

import Loadable from 'react-loadable'
export const ExploreView = Loadable({
  loader: () => import(/* webpackChunkName: "explore" */ './containers/ExploreView'),
  loading: () => null,
})

Error: Cannot find module ‘./2.serverRenderer.js’ at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Function.requireEnsure [as e] (C:\Users\Adrien\Documents\Dev\front-end-ssr\dist\server\webpack:\webpack\bootstrap 134319b5727946bc9a01:39:1) at loader (C:\Users\Adrien\Documents\Dev\front-end-ssr\dist\server\webpack:\src\universal\routes\explore\index.js:9:17) at C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-loadable\lib\index.js:28:12 at capture (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-loadable\lib\index.js:21:17) at load (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-loadable\lib\index.js:27:18) at new LoadableComponent (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-loadable\lib\index.js:149:15) at C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactCompositeComponent.js:294:18 at measureLifeCyclePerf (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactCompositeComponent.js:75:12) at ReactCompositeComponentWrapper._constructComponentWithoutOwner (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactCompositeComponent.js:293:16) at ReactCompositeComponentWrapper._constructComponent (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactCompositeComponent.js:279:21) at ReactCompositeComponentWrapper.mountComponent (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactCompositeComponent.js:187:21) at Object.mountComponent (C:\Users\Adrien\Documents\Dev\front-end-ssr\node_modules\react-dom\lib\ReactReconciler.js:45:35)

(I’m investigating clearing the require cache after compile as an alternative solution)