vitaliy-bobrov / angular-hot-loader

🔥 Webpack Hot Module Replacement for Angular 1.x applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

FDiskas opened this issue · comments

ERROR in [at-loader] src\app\Users\UsersModule.ts:1:26
    TS2339: Property 'hot' does not exist on type 'NodeModule'.

modules

angular-hot-loader@0.8.6
webpack@2.2.1
webpack-dev-server@2.4.1

p.s. using a typesript ❌

Probably missing type definition

@types/webpack-env

But still could not get it work

@FDiskas
possible related issue solutions:
webpack-contrib/webpack-hot-middleware#89
https://medium.com/@GiacomoRebonato/hot-module-reloading-with-typescript-and-react-9cc8768e8f24#.rtytl1hkc - article about react but issue related to code that added to app to enable HMR

if (module.hot) {
      module.hot.accept();...

a workaround is:
declare var module: any
it's not perfect but it works😳

Another workaround is

if ((module as any).hot) {
  (module as any).hot.accept('...

@ackvf this worked for me. thank you!

works fine :)

While including webpack-env works, it causes a lot of clashing with other libraries. @ackvf solution works spot on.

Well, it could be dealt with like this:

declare interface NodeModule {
  hot: {
    accept(path?: () => void, callback?: () => void): void
  }
}

I had to make a slight modification to @yyynnn 's code to get it to work for me:

declare interface NodeModule {
  hot: {
    accept(path?: string, fn: () => void, callback?: () => void): void;
  };
}

I put this in my globals.d.ts file, just FYI.

commented

adding "webpack-env" to the types array in my tsconfig.json got it working for me!

If you're running into this using react hot loader, might want to check this out:
https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md#common-typescript-mistake

Also you can save a bit of code by getting rid of if (module.hot) and just use

if (process.env.NODE_ENV === 'development') {
  (module as any).hot?.accept('./App', render)
}

(I'm dealing with React, but same thing)

Just add for this lines above

 @ts-ignore