webpack-hot-middleware icon indicating copy to clipboard operation
webpack-hot-middleware copied to clipboard

Handle when `unacceptedModule` is not in `moduleMap`

Open vjpr opened this issue 7 years ago • 3 comments

I encountered a problem where the module that could not be updated was not in the moduleMap resulting in - undefined being printed when listing the modules that couldn't be hot updated.

https://github.com/webpack-contrib/webpack-hot-middleware/blob/78c9e7e37e63a0b61460010a36fd608df5fb535e/process-update.js#L88-L108

screen shot 2018-05-04 at 11 29 16 pm

vjpr avatar May 06 '18 15:05 vjpr

This is a good idea, i’d take a pull request for it.

The other option might be to remove this feature entirely and advise people to use the named modules plugin

glenjamin avatar May 07 '18 14:05 glenjamin

I encountered a similar issue but in my case moduleMap didn't contain renewedModules which resulted in a bunch of - undefined in the console. Is there a known solution for that?

renewedModules = [
"./src/scripts/apps/enb/routes/records.js",
"./src/scripts/apps/enb/routes/index.js",
"./src/scripts/apps/enb/app.js"
]
moduleMap = {
"./src/scripts/apps/enb/routes/records.js": "./src/scripts/apps/enb/routes/records.js"
}
      if(!renewedModules || renewedModules.length === 0) {
        console.log("[HMR] Nothing hot updated.");
      } else {
        console.log("[HMR] Updated modules:");
        renewedModules.forEach(function(moduleId) {
          console.log("[HMR]  - " + moduleMap[moduleId]);
        });
      }

"./src/scripts/apps/enb/app.js" This module contains React Hot Loader and wraps the module with hot(module)(MyApp)

"./src/scripts/apps/enb/routes/index.js" Routes/index contains dynamic imports for code splitting <Route path="/records" component={load(() => import(/* webpackChunkName: 'enb.records' */ './records'))} />

"./src/scripts/apps/enb/routes/records.js" This module is where the change actually occurred.

Is it possible that because of the code splitting the module map doesn't have any information about its parent modules and hence it prints out undefined? Would it be possible in this case to print out renewedModule id as a fallback?

Zdend avatar Sep 17 '18 23:09 Zdend

Yep, that seems sensible, i’d take a PR.

glenjamin avatar Sep 18 '18 07:09 glenjamin