LoginSignup
5
3

More than 5 years have passed since last update.

React: TypeScript の lint で module.hot 周りでエラーが出た際の解決方法

Posted at

TypeScript の lint でmodule.hot周りでエラーが出る

ReactやPreactでHMRをやろうとする際、TypeScript (tsx) で書いていると lint で怒られることがある。

Property 'hot' does not exist on type 'NodeModule'

@types/webpack-env を追加すればよいだけ

yarn add --dev @types/webpack-envしよう。

if (module.hot) {
  module.hot.accept("./Top.tsx", () => {
    const AppHMR = require("./Top"); // eslint-disable-line global-require, @typescript-eslint/no-var-requires
    render(<AppHMR.default />, document.querySelector("#app"));
  });

毎回調べてる気がしたので、もういい加減書き残しておこうと思いました。

参考

5
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3