Skip to content

Angular 6 AOT compilation not working - Error in AngularCompilerPlugin #12248

@anbaran

Description

@anbaran

Bug Report or Feature Request (mark with an x)

- [ x ] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

Linux Ubuntu VERSION="16.04.4 LTS (Xenial Xerus)
node v10.10.0
npm 6.4.1
ng (none, this project is not managed by Angular CLI)
Angular 6
ngtools/webpack 1.10.2

"dependencies": {
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/forms": "^6.0.0",
"@angular/http": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/router": "^6.0.0",
"@angular/upgrade": "^6.0.0",
"angular-in-memory-web-api": "^0.6.0",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.24"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.0",
"@ngtools/webpack": "1.10.2",
"@types/node": "^6.0.45",
"lodash": "^4.16.2",
"typescript": "2.7.2",
"grunt": "~0.4.5",
"grunt-cli": "1.2.0",
"grunt-webpack": "3.1.3",
"webpack": "3.12.0",
"raw-loader": "0.5.1"
},

Repro steps

I created minimal sample app to reproduce this error. The key point is that this app is AOT compiled using the webpack plugin @ngtools/webpack.

How to reproduce

  1. git clone https://github.com/anbaran/ngtools-webpack-error.git
  2. cd ngtools-webpack-error/
  3. install grunt cli with: npm install -g grunt-cli (if you don't already have it)
  4. Run: npm install
  5. Run: grunt (this step will start AOT compilation of that project)

The log given by the failure

ERROR in : TypeError: Cannot read property 'getTsProgram' of undefined
    at AngularCompilerPlugin._getTsProgram (<project-location>/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:189:62)
    at getTypeChecker (<project-location>/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:533:43)
    at ast_helpers_1.collectDeepNodes.filter (<project-location>/node_modules/@ngtools/webpack/src/transformers/remove_decorators.js:14:60)
    at Array.filter (<anonymous>)
    at standardTransform (<project-location>/node_modules/@ngtools/webpack/src/transformers/remove_decorators.js:14:14)
    at transformer (<project-location>/node_modules/@ngtools/webpack/src/transformers/make_transform.js:14:25)
    at <project-location>/node_modules/typescript/lib/typescript.js:2892:86
    at reduceLeft (<project-location>/node_modules/typescript/lib/typescript.js:2585:30)
    at <project-location>/node_modules/typescript/lib/typescript.js:2892:42
    at transformRoot (<project-location>/node_modules/typescript/lib/typescript.js:67846:82)

Desired functionality

It should be possible to compile Angular 6 projects with Ahead-of-Time compiler using @ngtools/webpack plugin (without using the Angular CLI)

Mention any other details that might be useful

Using @ngtools/webpack for AOT compiling works in my setup until version 1.8 which is ok for Angular 5. However, Angular 6 requires to have at least @ngtools/webpack 1.10.0 which causes the above error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions