ng build --prod build failed after running npm ins

2019-04-10 11:47发布

问题:

Here is the error getting in prod build

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/var/www/project/src'
 @ ./src/main.ts 4:0-74
 @ multi ./src/main.ts

Getting error because new versions of packages being installed after running npm install. Cannot share packages version differences because the list is too lengthy. Its working with aot false but don't want to build with aot false. Not able to find out which package is responsible for this.

回答1:

Try

npm i enhanced-resolve@3.3.0

or add it to your shrinkwrap.json or package-lock.json or yarn.lock or update angular-cli as said Filipe Silva

We've released 1.2.4/1.3.0-rc.1 to fix this issue

I also had issue with enhanced-resolve: angular-cli didn't respect my --environment flag

See also this thread

  • https://github.com/angular/angular-cli/issues/7113


回答2:

  1. npm clean cache
  2. Delete node_modules
  3. Add "enhanced-resolve": "3.3.0" in your package.json
  4. run npm install
  5. rebuild !

I solved it with this thread

https://github.com/angular/angular-cli/issues/7113