I am experiencing a problem with hot-reloading in my Angular project. I recently upgraded it from version 15 to 17. Now, when I make changes to my code, I have to run ng build followed by ng serve to see the latest updates. However, I expect to see the latest changes without having to run ng build. It's very cumbersome to do this for every code change.
In my angular.json, I have the following configuration:
"build": {
"development": {
"aot": false
}
},
"serve": {
"configurations": {
"development": {
"liveReload": true
}
}
}
package.json:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng serve --configuration development",
"test": "ng test"
},
The methods I've tried so far include:
- Removing
node_modulesandpackage-lock.json, then runningnpm install. - Reloading the browser with 'Ctrl + F5'.
How can solve this problem?
Instead of manually removing
node_modulesandpackage-lock.json, you should have runnpm cito perform a clean install. This command requires bothpackage.jsonandpackage-lock.jsonand automatically removesnode_modulesif present. It also does not install newer package versions likenpm install. Check out npm-ci for more information.When encountering issues related to the Angular development server, you should restart it first. If unsuccessful, you can try to run
ng cache clean.I don't see anything wrong with your configuration. Also note by default,
ng buildcompiles a production version of your Angular app in thedistfolder which is not what you want here.