angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.77k stars 11.97k forks source link

Aot build failed in angular build #8784

Closed sarathscs closed 5 years ago

sarathscs commented 6 years ago

Hi,

I am using following package.json in my application:

"dependencies": {
        "@angular/animations": "4.4.6",
        "@angular/cdk": "2.0.0-beta.11",
        "@angular/common": "4.4.6",
        "@angular/compiler": "4.4.6",
        "@angular/core": "4.4.6",
        "@angular/forms": "4.4.6",
        "@angular/http": "4.4.6",
        "@angular/material": "2.0.0-beta.11",
        "@angular/platform-browser": "4.4.6",
        "@angular/platform-browser-dynamic": "4.4.6",
        "@angular/router": "4.4.6",
        "@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.28",
        "angular2-drag-scroll": "1.4.4",
        "angular2-image-zoom": "1.2.1",
        "angular2-modal": "3.0.1",
        "angular2-moment": "1.7.0",
        "angular2-notifications": "0.7.8",
        "angularfire2": "4.0.0-rc.1",
        "aws-sdk": "2.88.0",
        "core-js": "2.4.1",
        "firebase": "3.6.6",
        "lodash": "4.17.4",
        "moment": "2.18.1",
        "ng2-auto-complete": "0.12.0",
        "ng2-canvas-whiteboard": "1.4.0",
        "ng2-file-upload": "1.2.1",
        "ng2-google-place-autocomplete": "1.4.2",
        "ng2-order-pipe": "0.1.5",
        "ng2-pagination": "2.0.2",
        "ng2-progressbar": "1.3.0",
        "ng2-toastr": "4.1.2",
        "ngx-infinite-scroll": "0.5.2",
        "ngx-pipes": "1.6.3",
        "ngx-rating": "0.0.9",
        "primeng": "4.1.1",
        "rxjs": "5.1.0",
        "time-ago-pipe": "1.2.1",
        "zone.js": "0.8.4"
    },
    "devDependencies": {
        "@angular/cli": "1.5.3",
        "@angular/compiler-cli": "4.4.6",
        "@angular/language-service": "4.4.6",
        "@types/jasmine": "~2.5.53",
        "@types/jasminewd2": "~2.0.2",
        "@types/node": "6.0.85",
        "codelyzer": "~3.0.1",
        "jasmine-core": "~2.6.2",
        "jasmine-spec-reporter": "~4.1.0",
        "karma": "~1.7.0",
        "karma-chrome-launcher": "~2.1.1",
        "karma-cli": "~1.0.1",
        "karma-coverage-istanbul-reporter": "1.2.1",
        "karma-jasmine": "~1.1.0",
        "karma-jasmine-html-reporter": "0.2.2",
        "protractor": "~5.1.2",
        "ts-node": "~3.0.4",
        "tslint": "~5.3.2",
        "typescript": "~2.3.3",
        "webpack": "3.7.1"
    }

In ng build it will not have any problem .This issue only happeing is AOT build

Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'projectfolder/src'resolve './$$_gendir/app/app.module.ngfactory'

Please suggest

psmyrdek commented 6 years ago

Additional setup for AOT is described here - https://angular.io/guide/upgrade#aot-compile-the-hybrid-app. Maybe you will find solution there.

I had the same error while running ng build --prod because AOT is set to true by default, but to use AOT, you need to make some additional changes in your project upfront.

clydin commented 6 years ago

@psmyrdek A newly generated CLI project does not require any changes to support AOT. Running ng build --prod should be all that is needed.

@sarathscs I would recommend upgrading to the latest stable version of the CLI as well as reviewing the project's dependencies to ensure there are no peer dependency warnings. Also webpack should not be present within the project's dev dependencies. After adjusting, remove the node_modules directory and package lock file and re-install. Note that there may be two peer dependency warnings for @schematics/schematics & @schematics/angular. These can be ignored for now and will be corrected soon.

ianfdk commented 6 years ago

I'm getting the same problem. ng build -op dist -w works just fine, but ng build --prod fails

Angular CLI: 1.6.0 Node: 7.0.0

package.json:

"dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@ngx-translate/core": "^9.0.1",
    "@swimlane/ngx-charts": "^7.0.1",
    "@types/lodash": "^4.14.58",
    "angular2-notifications": "^0.9.6",
    "angulartics2": "^4.4.0",
    "bootstrap": "^3.3.7",
    "bootstrap-sass": "^3.3.7",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.4.1",
    "d3": "^4.9.1",
    "file-saver": "^1.3.3",
    "lodash": "^4.17.4",
    "moment": "^2.18.1",
    "ngx-bootstrap": "^2.0.0-beta.10",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.6.0",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@angular-devkit/schematics": "^0.0.40",
    "@types/jasmine": "~2.8.2",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~8.0.58",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.2.1",
    "ts-node": "~4.0.1",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
ianfdk commented 6 years ago

Is there a way to debug the cause of ngFactory not being created?

jgf5013 commented 6 years ago

I'm getting this same error with a hybrid app. I know it's not the OP's question but for those of you who stumble across this this thread with a hybrid app, as @psmyrdek said - there are additional steps for running hybrid apps through ng serve <appname> --aot or ng build <appname> --prod. For instance, arrow functions are not supported...

alan-agius4 commented 5 years ago

@jgf5013, those errors are related to the fact that your application is not AOT compatible.

Here's a guide on what you need to do to make your application AOT compatible https://angular.io/guide/aot-compiler

Please update to the most recent Angular CLI version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

angular-automatic-lock-bot[bot] commented 5 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.