Module not found: Error: Can’t resolve ‘./$$_gendir/app/app.module.ngfactory’

introduction

error in packaging to generate dist file when creating angular project:

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\web\task\src'
 @ ./src/main.ts 3:0-74
 @ multi ./src/main.ts

solution:
replace ng build — prod with ng build — env=prod, and then compile successfully.
reason: this is not based on aot, ng build – env = prod: replace environment.prod.ts with environment.prod.ts, but it’s a simple ng build. Ng build — prod: replace the improved version with aot + environment.prod.ts (previously, it was ng build — prod — aot)

Read More: