Angular library build error: TypeError: Cannot read property 'type' of null










4















In Angular v6, when attempting to build my library I am running into an extremely non-descriptive BUILD ERROR Cannot read property 'type' of null



BUILD ERROR
Cannot read property 'type' of null
TypeError: Cannot read property 'type' of null
at /Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:15378:27
at Array.forEach (<anonymous>)
at removeSummaryDuplicates (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:15377:11)
at TemplateParser.tryParseHtml (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14806:34)
at TemplateParser.tryParse (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14799:21)
at TemplateParser.parse (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14780:27)
at AotCompiler._parseTemplate (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20483:43)
at AotCompiler._createTypeCheckBlock (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20250:23)
at /Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20220:27
at Array.forEach (<anonymous>)


Having already solved this problem, I'm making this post to help anyone else running into this issue.










share|improve this question


























    4















    In Angular v6, when attempting to build my library I am running into an extremely non-descriptive BUILD ERROR Cannot read property 'type' of null



    BUILD ERROR
    Cannot read property 'type' of null
    TypeError: Cannot read property 'type' of null
    at /Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:15378:27
    at Array.forEach (<anonymous>)
    at removeSummaryDuplicates (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:15377:11)
    at TemplateParser.tryParseHtml (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14806:34)
    at TemplateParser.tryParse (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14799:21)
    at TemplateParser.parse (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14780:27)
    at AotCompiler._parseTemplate (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20483:43)
    at AotCompiler._createTypeCheckBlock (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20250:23)
    at /Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20220:27
    at Array.forEach (<anonymous>)


    Having already solved this problem, I'm making this post to help anyone else running into this issue.










    share|improve this question
























      4












      4








      4








      In Angular v6, when attempting to build my library I am running into an extremely non-descriptive BUILD ERROR Cannot read property 'type' of null



      BUILD ERROR
      Cannot read property 'type' of null
      TypeError: Cannot read property 'type' of null
      at /Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:15378:27
      at Array.forEach (<anonymous>)
      at removeSummaryDuplicates (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:15377:11)
      at TemplateParser.tryParseHtml (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14806:34)
      at TemplateParser.tryParse (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14799:21)
      at TemplateParser.parse (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14780:27)
      at AotCompiler._parseTemplate (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20483:43)
      at AotCompiler._createTypeCheckBlock (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20250:23)
      at /Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20220:27
      at Array.forEach (<anonymous>)


      Having already solved this problem, I'm making this post to help anyone else running into this issue.










      share|improve this question














      In Angular v6, when attempting to build my library I am running into an extremely non-descriptive BUILD ERROR Cannot read property 'type' of null



      BUILD ERROR
      Cannot read property 'type' of null
      TypeError: Cannot read property 'type' of null
      at /Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:15378:27
      at Array.forEach (<anonymous>)
      at removeSummaryDuplicates (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:15377:11)
      at TemplateParser.tryParseHtml (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14806:34)
      at TemplateParser.tryParse (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14799:21)
      at TemplateParser.parse (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14780:27)
      at AotCompiler._parseTemplate (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20483:43)
      at AotCompiler._createTypeCheckBlock (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20250:23)
      at /Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20220:27
      at Array.forEach (<anonymous>)


      Having already solved this problem, I'm making this post to help anyone else running into this issue.







      angular angular-aot






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 26 '18 at 2:40









      JohnJohn

      2,7681229




      2,7681229






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Update



          It seems like my diagnosis of this issue was incorrect (it's been so long now I can't remember exactly show I fixed it). Check out this issue in the Angular repo for what sounds like the correct diagnosis,



          Original answer:



          So after a LOT of debugging, I figured it out:



          My custom library, let call it library A, imports another custom library, library B, into library A's NgModule. Library B exports several components and modules from it's main NgModule. The problem was that, while library B exported the components and modules from it's NgModule, I failed to also export those components and modules via javascript/typescript. The solution was to make sure to export any components / modules via typescript that I exported in the NgModule.



          Example problem code



          import NgModule from '@angular/core';
          import CommonModule from '@angular/common';
          import LibraryBComponent from './library-b.component';

          @NgModule(
          imports: [CommonModule],
          declarations: [LibraryBComponent],
          exports: [LibraryBComponent],
          )
          export class LibraryBModule


          Solution code



          import NgModule from '@angular/core';
          import CommonModule from '@angular/common';
          import LibraryBComponent from './library-b.component';

          export LibraryBComponent // <-- addition

          @NgModule(
          imports: [CommonModule],
          declarations: [LibraryBComponent],
          exports: [LibraryBComponent],
          )
          export class LibraryBModule





          share|improve this answer

























          • Unfortunatelly I'm exactly in the same situation and this solution does not work for me. In a way it makes sense because the component I'm exporting is already exported from it's own file via public_api.ts barrel.

            – George Knap
            Aug 24 '18 at 9:10











          • @GeorgeKnap it's been long enough that I don't remember too many details of this problem, but I think I ended up fixing things by creating a new, working, blank angular app, porting over my modules and code piece by piece, and incrementally rebuilding the app along the way searching for build errors. That way I was able to figure out exactly what code broke things. It was an extremely time consuming debugging process.

            – John
            Aug 24 '18 at 10:09











          • @GeorgeKnap Also, I may be remembering this incorrectly, but I think I ran into this problem while upgrading from angular v5 to v6, and I think one of the problems was that my polyfills.ts file was missing a required polyfill (I think the Reflect api, but I'm not sure).

            – John
            Aug 24 '18 at 10:14


















          0














          My issue was on <projectRoot>/tsconfig.json (you can check it on #24143(comment))



          Basically I had to remove the paths from tsconfig.json like:



           "library-b": [
          "dist/library-b"
          ],
          "library-b/*": [
          "dist/library-b/*"
          ]





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50538843%2fangular-library-build-error-typeerror-cannot-read-property-type-of-null%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Update



            It seems like my diagnosis of this issue was incorrect (it's been so long now I can't remember exactly show I fixed it). Check out this issue in the Angular repo for what sounds like the correct diagnosis,



            Original answer:



            So after a LOT of debugging, I figured it out:



            My custom library, let call it library A, imports another custom library, library B, into library A's NgModule. Library B exports several components and modules from it's main NgModule. The problem was that, while library B exported the components and modules from it's NgModule, I failed to also export those components and modules via javascript/typescript. The solution was to make sure to export any components / modules via typescript that I exported in the NgModule.



            Example problem code



            import NgModule from '@angular/core';
            import CommonModule from '@angular/common';
            import LibraryBComponent from './library-b.component';

            @NgModule(
            imports: [CommonModule],
            declarations: [LibraryBComponent],
            exports: [LibraryBComponent],
            )
            export class LibraryBModule


            Solution code



            import NgModule from '@angular/core';
            import CommonModule from '@angular/common';
            import LibraryBComponent from './library-b.component';

            export LibraryBComponent // <-- addition

            @NgModule(
            imports: [CommonModule],
            declarations: [LibraryBComponent],
            exports: [LibraryBComponent],
            )
            export class LibraryBModule





            share|improve this answer

























            • Unfortunatelly I'm exactly in the same situation and this solution does not work for me. In a way it makes sense because the component I'm exporting is already exported from it's own file via public_api.ts barrel.

              – George Knap
              Aug 24 '18 at 9:10











            • @GeorgeKnap it's been long enough that I don't remember too many details of this problem, but I think I ended up fixing things by creating a new, working, blank angular app, porting over my modules and code piece by piece, and incrementally rebuilding the app along the way searching for build errors. That way I was able to figure out exactly what code broke things. It was an extremely time consuming debugging process.

              – John
              Aug 24 '18 at 10:09











            • @GeorgeKnap Also, I may be remembering this incorrectly, but I think I ran into this problem while upgrading from angular v5 to v6, and I think one of the problems was that my polyfills.ts file was missing a required polyfill (I think the Reflect api, but I'm not sure).

              – John
              Aug 24 '18 at 10:14















            1














            Update



            It seems like my diagnosis of this issue was incorrect (it's been so long now I can't remember exactly show I fixed it). Check out this issue in the Angular repo for what sounds like the correct diagnosis,



            Original answer:



            So after a LOT of debugging, I figured it out:



            My custom library, let call it library A, imports another custom library, library B, into library A's NgModule. Library B exports several components and modules from it's main NgModule. The problem was that, while library B exported the components and modules from it's NgModule, I failed to also export those components and modules via javascript/typescript. The solution was to make sure to export any components / modules via typescript that I exported in the NgModule.



            Example problem code



            import NgModule from '@angular/core';
            import CommonModule from '@angular/common';
            import LibraryBComponent from './library-b.component';

            @NgModule(
            imports: [CommonModule],
            declarations: [LibraryBComponent],
            exports: [LibraryBComponent],
            )
            export class LibraryBModule


            Solution code



            import NgModule from '@angular/core';
            import CommonModule from '@angular/common';
            import LibraryBComponent from './library-b.component';

            export LibraryBComponent // <-- addition

            @NgModule(
            imports: [CommonModule],
            declarations: [LibraryBComponent],
            exports: [LibraryBComponent],
            )
            export class LibraryBModule





            share|improve this answer

























            • Unfortunatelly I'm exactly in the same situation and this solution does not work for me. In a way it makes sense because the component I'm exporting is already exported from it's own file via public_api.ts barrel.

              – George Knap
              Aug 24 '18 at 9:10











            • @GeorgeKnap it's been long enough that I don't remember too many details of this problem, but I think I ended up fixing things by creating a new, working, blank angular app, porting over my modules and code piece by piece, and incrementally rebuilding the app along the way searching for build errors. That way I was able to figure out exactly what code broke things. It was an extremely time consuming debugging process.

              – John
              Aug 24 '18 at 10:09











            • @GeorgeKnap Also, I may be remembering this incorrectly, but I think I ran into this problem while upgrading from angular v5 to v6, and I think one of the problems was that my polyfills.ts file was missing a required polyfill (I think the Reflect api, but I'm not sure).

              – John
              Aug 24 '18 at 10:14













            1












            1








            1







            Update



            It seems like my diagnosis of this issue was incorrect (it's been so long now I can't remember exactly show I fixed it). Check out this issue in the Angular repo for what sounds like the correct diagnosis,



            Original answer:



            So after a LOT of debugging, I figured it out:



            My custom library, let call it library A, imports another custom library, library B, into library A's NgModule. Library B exports several components and modules from it's main NgModule. The problem was that, while library B exported the components and modules from it's NgModule, I failed to also export those components and modules via javascript/typescript. The solution was to make sure to export any components / modules via typescript that I exported in the NgModule.



            Example problem code



            import NgModule from '@angular/core';
            import CommonModule from '@angular/common';
            import LibraryBComponent from './library-b.component';

            @NgModule(
            imports: [CommonModule],
            declarations: [LibraryBComponent],
            exports: [LibraryBComponent],
            )
            export class LibraryBModule


            Solution code



            import NgModule from '@angular/core';
            import CommonModule from '@angular/common';
            import LibraryBComponent from './library-b.component';

            export LibraryBComponent // <-- addition

            @NgModule(
            imports: [CommonModule],
            declarations: [LibraryBComponent],
            exports: [LibraryBComponent],
            )
            export class LibraryBModule





            share|improve this answer















            Update



            It seems like my diagnosis of this issue was incorrect (it's been so long now I can't remember exactly show I fixed it). Check out this issue in the Angular repo for what sounds like the correct diagnosis,



            Original answer:



            So after a LOT of debugging, I figured it out:



            My custom library, let call it library A, imports another custom library, library B, into library A's NgModule. Library B exports several components and modules from it's main NgModule. The problem was that, while library B exported the components and modules from it's NgModule, I failed to also export those components and modules via javascript/typescript. The solution was to make sure to export any components / modules via typescript that I exported in the NgModule.



            Example problem code



            import NgModule from '@angular/core';
            import CommonModule from '@angular/common';
            import LibraryBComponent from './library-b.component';

            @NgModule(
            imports: [CommonModule],
            declarations: [LibraryBComponent],
            exports: [LibraryBComponent],
            )
            export class LibraryBModule


            Solution code



            import NgModule from '@angular/core';
            import CommonModule from '@angular/common';
            import LibraryBComponent from './library-b.component';

            export LibraryBComponent // <-- addition

            @NgModule(
            imports: [CommonModule],
            declarations: [LibraryBComponent],
            exports: [LibraryBComponent],
            )
            export class LibraryBModule






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 19 '18 at 11:15

























            answered May 26 '18 at 2:40









            JohnJohn

            2,7681229




            2,7681229












            • Unfortunatelly I'm exactly in the same situation and this solution does not work for me. In a way it makes sense because the component I'm exporting is already exported from it's own file via public_api.ts barrel.

              – George Knap
              Aug 24 '18 at 9:10











            • @GeorgeKnap it's been long enough that I don't remember too many details of this problem, but I think I ended up fixing things by creating a new, working, blank angular app, porting over my modules and code piece by piece, and incrementally rebuilding the app along the way searching for build errors. That way I was able to figure out exactly what code broke things. It was an extremely time consuming debugging process.

              – John
              Aug 24 '18 at 10:09











            • @GeorgeKnap Also, I may be remembering this incorrectly, but I think I ran into this problem while upgrading from angular v5 to v6, and I think one of the problems was that my polyfills.ts file was missing a required polyfill (I think the Reflect api, but I'm not sure).

              – John
              Aug 24 '18 at 10:14

















            • Unfortunatelly I'm exactly in the same situation and this solution does not work for me. In a way it makes sense because the component I'm exporting is already exported from it's own file via public_api.ts barrel.

              – George Knap
              Aug 24 '18 at 9:10











            • @GeorgeKnap it's been long enough that I don't remember too many details of this problem, but I think I ended up fixing things by creating a new, working, blank angular app, porting over my modules and code piece by piece, and incrementally rebuilding the app along the way searching for build errors. That way I was able to figure out exactly what code broke things. It was an extremely time consuming debugging process.

              – John
              Aug 24 '18 at 10:09











            • @GeorgeKnap Also, I may be remembering this incorrectly, but I think I ran into this problem while upgrading from angular v5 to v6, and I think one of the problems was that my polyfills.ts file was missing a required polyfill (I think the Reflect api, but I'm not sure).

              – John
              Aug 24 '18 at 10:14
















            Unfortunatelly I'm exactly in the same situation and this solution does not work for me. In a way it makes sense because the component I'm exporting is already exported from it's own file via public_api.ts barrel.

            – George Knap
            Aug 24 '18 at 9:10





            Unfortunatelly I'm exactly in the same situation and this solution does not work for me. In a way it makes sense because the component I'm exporting is already exported from it's own file via public_api.ts barrel.

            – George Knap
            Aug 24 '18 at 9:10













            @GeorgeKnap it's been long enough that I don't remember too many details of this problem, but I think I ended up fixing things by creating a new, working, blank angular app, porting over my modules and code piece by piece, and incrementally rebuilding the app along the way searching for build errors. That way I was able to figure out exactly what code broke things. It was an extremely time consuming debugging process.

            – John
            Aug 24 '18 at 10:09





            @GeorgeKnap it's been long enough that I don't remember too many details of this problem, but I think I ended up fixing things by creating a new, working, blank angular app, porting over my modules and code piece by piece, and incrementally rebuilding the app along the way searching for build errors. That way I was able to figure out exactly what code broke things. It was an extremely time consuming debugging process.

            – John
            Aug 24 '18 at 10:09













            @GeorgeKnap Also, I may be remembering this incorrectly, but I think I ran into this problem while upgrading from angular v5 to v6, and I think one of the problems was that my polyfills.ts file was missing a required polyfill (I think the Reflect api, but I'm not sure).

            – John
            Aug 24 '18 at 10:14





            @GeorgeKnap Also, I may be remembering this incorrectly, but I think I ran into this problem while upgrading from angular v5 to v6, and I think one of the problems was that my polyfills.ts file was missing a required polyfill (I think the Reflect api, but I'm not sure).

            – John
            Aug 24 '18 at 10:14













            0














            My issue was on <projectRoot>/tsconfig.json (you can check it on #24143(comment))



            Basically I had to remove the paths from tsconfig.json like:



             "library-b": [
            "dist/library-b"
            ],
            "library-b/*": [
            "dist/library-b/*"
            ]





            share|improve this answer



























              0














              My issue was on <projectRoot>/tsconfig.json (you can check it on #24143(comment))



              Basically I had to remove the paths from tsconfig.json like:



               "library-b": [
              "dist/library-b"
              ],
              "library-b/*": [
              "dist/library-b/*"
              ]





              share|improve this answer

























                0












                0








                0







                My issue was on <projectRoot>/tsconfig.json (you can check it on #24143(comment))



                Basically I had to remove the paths from tsconfig.json like:



                 "library-b": [
                "dist/library-b"
                ],
                "library-b/*": [
                "dist/library-b/*"
                ]





                share|improve this answer













                My issue was on <projectRoot>/tsconfig.json (you can check it on #24143(comment))



                Basically I had to remove the paths from tsconfig.json like:



                 "library-b": [
                "dist/library-b"
                ],
                "library-b/*": [
                "dist/library-b/*"
                ]






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 10:09









                Fabio PicheliFabio Picheli

                616520




                616520



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50538843%2fangular-library-build-error-typeerror-cannot-read-property-type-of-null%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                    Museum of Modern and Contemporary Art of Trento and Rovereto