PatrickJS / angular-hmr

:fire: Angular Hot Module Replacement for Hot Module Reloading
https://patrickjs.com
Apache License 2.0
505 stars 46 forks source link

Webpack 4 / Angular 6 support #74

Closed maroy1986 closed 5 years ago

maroy1986 commented 6 years ago

Hey there,

Maybe you already know, but this library doesn't work anymore with WebPack 4 and Angular 6. Here's what I get when trying to ng serve.

image

This is most likely related to the big changes that happened in WebPack 4. Is there any plans to upgrade this? If not on your end, I might peek at it if I don't found any other alternatives.

Thanks.

My CLI infos are the following :

Angular CLI: 6.0.0-rc.2
Node: 8.11.1
OS: win32 x64
Angular: 6.0.0-rc.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 6.0.0-rc.1
@angular/cli: 6.0.0-rc.2
@angular/flex-layout: 5.0.0-beta.14
@angular/material: 6.0.0-rc.1
@angular-devkit/architect: 0.5.4
@angular-devkit/build-angular: 0.5.4
@angular-devkit/build-optimizer: 0.5.4
@angular-devkit/core: 0.5.4
@angular-devkit/schematics: 0.5.4
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 6.0.0-rc.2.4
@schematics/angular: 0.5.4
@schematics/update: 0.5.4
typescript: 2.7.2
webpack: 4.5.0
ghost commented 6 years ago

I'm reproducing this error too. Angular 6 will be out soon.

I fixed it by adding declare var module: {}; above the module line in main.ts

However, it reloads the window on scss inline-template style.

maroy1986 commented 6 years ago

This is also tracked here in the CLI issues : https://github.com/angular/angular-cli/issues/10268

enten commented 6 years ago

About error TS2304: Cannot find name 'module': do you think may it due to a missing typescript definition?

Can you try to npm install --save-dev @types/node@~8.9.4 @types/webpack-env@^1.13.6 and add the directive below in your src/typings.d.ts?

///<reference types="webpack-env" />
TheAifam5 commented 6 years ago

@enten that works. Thank you :)

maroy1986 commented 5 years ago

Somehow, this started working again, weird but I'm gonna close this issue and pretend it was something on my end.

rafa-suagu commented 5 years ago

@maroy1986 is very strange but I have two equal projects (same config files, same versions, same node, same yarn, etc...) and one works properly and the other throws the error.

I found here https://github.com/angular/angular-cli/wiki/stories-configure-hmr one thing that solves the problem but I only need in one of the two projects.

Add the necessary types to src/tsconfig.app.json { ... "compilerOptions": { ... "types": ["node"] }, }