question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`module.hot.invalidate` is not a function

See original GitHub issue

I am trying this plugin with webpack-dev-server. I followed the instructions to add this plugin to code and also checked example in webpack-dev-server in examples directory.

This is my devServer config:

    devServer: {
      host: '0.0.0.0',
      historyApiFallback: true,
      hot: true,
      clientLogLevel: 'info',
      inline: true,
      liveReload: false,
      overlay: true,
      port: 8080,
    },

I am also using following code snippet to use HMR:-

if (module.hot) {
    module.hot.accept('./app', () => {
     const App = require('./app').default
     ReactDOM.render(<App />, root);
})
}

After adding the plugin to my webpack.config.js, I changed the label text of Input component. (The input component and the component in which it is used both are functional components). I am getting following error:-

TypeError
module.hot.invalidate is not a function

Call Stack
 Object.eval
  //path of component
 eval
  //path of component
 Object..//path of component
  58.009bff0c7f3cf3782d9f.hot-update.js:6:1
 __webpack_require__
  main.js:794:31
 hotApply
  main.js:710:14
 undefined
  main.js:364:22

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
pmmmwhcommented, Aug 7, 2020

Below is an example how I write my components most of the time. Will it work if I do changes in presentational.js?

It should be fine - state should be preserved without any problems. If you do hit anything though, you might have to report to Redux instead because it’s most likely that they are “incompatible” with React’s internals.

(I haven’t used connect in a while and I assume it does follow the PascalCase rule for component names within it’s internals)

1reaction
pmmmwhcommented, Aug 10, 2020

@pmmmwh Thanks. Adding the --hot flag worked for me. But I have one question that I have hot: true in my devServer config in webpack. Do I still need to pass this flag?

It is a tiny bit different - devServer config flags are only read by WDS but not Webpack - so when you create dev builds it won’t kick into action.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hot Module Replacement - webpack
When invalidate is called, the dispose handler will be eventually called and fill module.hot.data . If dispose handler is not registered, an empty...
Read more >
A Deep Dive into Hot Module Replacement with Webpack ...
The console says that Hot Module Replacement is enabled. By default, it is not. This project is configured to run with HMR.
Read more >
Hot Reload doesn't work when starting inside a function #765
I tried placing a console.log inside the function that is passed into hot(module) but the console.log did not fire. Now I'm trying to...
Read more >
HMR API - Vite
Vite exposes its manual HMR API via the special import.meta.hot object: ... To indicate that the module is not hot-updatable, use hot.invalidate() ....
Read more >
React module loaded as a string with WebPack `asset/source ...
My test component is there tho, so I could mangle it with regex but I'd rather not if I can somehow remove that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found