Angular HMR not replacing/reloading components
Anyone out there who got this working and can provide a working sample app?
(from storybook https://github.com/chromaui/intro-storybook-angular-template )
Then HMR does not work as expected out of the box, but full reload does (ie [WDS] Live Reloading enabled.)
Then HMR doesn't reload anything. (no Live reload at all)
12.0.5 Behavior: no reload when updating angular components.
Error in console (chrome):
dev-server.js:60 Uncaught Error: [HMR] Hot Module Replacement is disabled.
at Object.5033 (dev-server.js:60)
at __webpack_require__ (bootstrap:19)
at __webpack_exec__ (polyfills.js:12907)
at polyfills.js:12908
at webpackJsonpCallback (jsonp chunk loading:35)
at polyfills.js:1
After editing a component (HTML) the console is "Stuck on" "[WDS] App hot update…"
Same result as for v11 (Then HMR does not work as expected out of the box, but full reload does (ie [WDS] Live Reloading enabled.)
and a solution seem to be to set the webpack target to web (instead of browser) for development. or to use a beta version of webpack-dev-server (ie 4.0.0-beta.x)
"target: 'web',
in "node_modules/@angular-devkit/build-webpack/package.json" the webpack-dev-server is used.
For "@angular-devkit/build-angular": "~12.0.5", webpack-dev-server version is 3.11.2
"peerDependencies": { "webpack": "^5.30.0", "webpack-dev-server": "^3.11.2" },
when updating Angular to v-next For "@angular-devkit/build-angular": "^12.1.0-next.6",webpack-dev-server version is lower , 3.1.4, the same as in 'build-angular' v11. (probably because they realized the issue with live reloading)
"peerDependencies": { "webpack": "^5.30.0", "webpack-dev-server": "^3.1.4" },
when using Angular 11 For "@angular-devkit/build-angular": "~0.1100.6"
"peerDependencies": { "webpack": "^4.6.0", "webpack-dev-server": "^3.1.4" },
Configuring according to the following resource, using @angular-builders/custom-webpack
did't help. HELP! =D
//package.json
"devDependencies": {
"@angular-builders/custom-webpack": "^12.1.0",
//angular.json
//replace "builder" in "build" and "serve"
//add customWebpackConfig with path to a new config file
//"builder": "@angular-devkit/build-angular:browser"
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "extra-webpack.config.ts",
"replaceDuplicatePlugins": true
},
//...
//replace "builder": "@angular-devkit/build-angular:dev-server",
"serve": {
"builder": "@angular-builders/custom-webpack:dev-server",
//extra-webpack.config.ts
import { Configuration } from "webpack";
export default {
target:"web",
// target: process.env.NODE_ENV === "development" ? "web" : "browserslist",
} as Configuration;
We have something similar as you presented. Did you delete package_lock, node_modules and do a fresh install?
In Angular 11.2.4 and with a fresh Angular 12.1.4 project, the setup with HRM works with no problem. Try with "@angular-builders/custom-webpack": "12.1.0", "@angular-devkit/build-angular": "^12.1.4" and it should work
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.