Switched angular 9 app to lazy loading to reduce main.js bundle size.
Works fine locally and loads the module upon hitting the route.
e.g. downloads the script http://localhost:port/name-module.js
After running npm run build the chunks are produced for all routes.
Since I'm loading my Angular app via Node.js Express app I have a html file where I included the main scripts.
e.g.
<script src="./angular/runtime-es2015.js" type="module"></script>
<script src="./angular/polyfills-es2015.js" type="module"></script>
<script src="./angular/main-es2015.js" type="module"></script>
Obviously, I need to include my chunks as well but thought the code would be in main.js to fetch the required chunk when the corresponding route is hit? In other words I don't have to explicitly define the script for those chunks in the html file shown above.
The error which I'm getting:
Uncaught (in promise): ChunkLoadError: Loading chunk 2 failed.
(missing: http://localhost:5000/2-es2015.js)
ChunkLoadError: Loading chunk 2 failed.
(missing: http://localhost:5000/2-es2015.js)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…