Get `Cannot read property 'type' of null` using Angular2 AoT ngc compiler with RC5

前端 未结 2 1172
北荒
北荒 2021-01-27 21:02

Update to Angular2 2.0.0-rc.5, run in browser without any warning, but when try AOT compile with ngc -p command, get the flowing error:

Here is my

相关标签:
2条回答
  • 2021-01-27 21:36

    Do not use default exports in your code:

    // somefile.ts
    export default function (...) {
        ...
    }
    ...
    // some-other-file.ts
    import whatevar from './somefile';
    

    use explicit names instead

    // somefile.ts
    export function whatevar(...) {
        ...
    }
    ...
    // some-other-file.ts
    import { whatevar } from './somefile';
    

    AOT is incompatible with default exports (among other things). But unlike other incompatibilities, this one generates the most cryptic error message ever.

    0 讨论(0)
  • 2021-01-27 21:41

    All these errors are related to AoT. This blog post explains the changes to be made in your code.

    Making your Angular 2 library statically analyzable for AoT

    1. const lambda => export function
    2. default export => named export
    3. private, protected accessors should be changed to public for any members accessed from template
    4. dynamic component template => static template
    5. moduleId should be set on components with templateUrl
    0 讨论(0)
提交回复
热议问题