How to bundle / include dependencies in Angular-CLI libraries












0















I'm having issues bundling dependencies.



My library package is a wrapper around @angular/material components.



I was surprised to find that everywhere I installed my library package also asked for @angular/material to be installed or I get an error.



There has to be a better way to do this right? I would like my package to be self-contained and "include" angular/material when it is installed.



I read that adding the following to the library's package.json



 "bundledDependencies": [
"@angular/material"
]


should solve this issue, but it didn't seem to work, or at least there has to be another step, because then I see this error when I am installing my package:




is missing a bundled dependency "@angular/material". This should be
reported to the package maintainer.




That error really makes it sound like I'm just missing something and this will work as I'm expecting. What am I missing?



I haven't been able to find any information on that error.



We would like to force the dependency to be installed to keep our library "modular" and self contained. In other words, we just want to install our library and automatically get all the dependencies that it needs.



We do not want to rely on the warning message from a peerDependencies.



It seems like this has to be a possible pattern, can anyone explain the point of bundledDependencies










share|improve this question





























    0















    I'm having issues bundling dependencies.



    My library package is a wrapper around @angular/material components.



    I was surprised to find that everywhere I installed my library package also asked for @angular/material to be installed or I get an error.



    There has to be a better way to do this right? I would like my package to be self-contained and "include" angular/material when it is installed.



    I read that adding the following to the library's package.json



     "bundledDependencies": [
    "@angular/material"
    ]


    should solve this issue, but it didn't seem to work, or at least there has to be another step, because then I see this error when I am installing my package:




    is missing a bundled dependency "@angular/material". This should be
    reported to the package maintainer.




    That error really makes it sound like I'm just missing something and this will work as I'm expecting. What am I missing?



    I haven't been able to find any information on that error.



    We would like to force the dependency to be installed to keep our library "modular" and self contained. In other words, we just want to install our library and automatically get all the dependencies that it needs.



    We do not want to rely on the warning message from a peerDependencies.



    It seems like this has to be a possible pattern, can anyone explain the point of bundledDependencies










    share|improve this question



























      0












      0








      0


      0






      I'm having issues bundling dependencies.



      My library package is a wrapper around @angular/material components.



      I was surprised to find that everywhere I installed my library package also asked for @angular/material to be installed or I get an error.



      There has to be a better way to do this right? I would like my package to be self-contained and "include" angular/material when it is installed.



      I read that adding the following to the library's package.json



       "bundledDependencies": [
      "@angular/material"
      ]


      should solve this issue, but it didn't seem to work, or at least there has to be another step, because then I see this error when I am installing my package:




      is missing a bundled dependency "@angular/material". This should be
      reported to the package maintainer.




      That error really makes it sound like I'm just missing something and this will work as I'm expecting. What am I missing?



      I haven't been able to find any information on that error.



      We would like to force the dependency to be installed to keep our library "modular" and self contained. In other words, we just want to install our library and automatically get all the dependencies that it needs.



      We do not want to rely on the warning message from a peerDependencies.



      It seems like this has to be a possible pattern, can anyone explain the point of bundledDependencies










      share|improve this question
















      I'm having issues bundling dependencies.



      My library package is a wrapper around @angular/material components.



      I was surprised to find that everywhere I installed my library package also asked for @angular/material to be installed or I get an error.



      There has to be a better way to do this right? I would like my package to be self-contained and "include" angular/material when it is installed.



      I read that adding the following to the library's package.json



       "bundledDependencies": [
      "@angular/material"
      ]


      should solve this issue, but it didn't seem to work, or at least there has to be another step, because then I see this error when I am installing my package:




      is missing a bundled dependency "@angular/material". This should be
      reported to the package maintainer.




      That error really makes it sound like I'm just missing something and this will work as I'm expecting. What am I missing?



      I haven't been able to find any information on that error.



      We would like to force the dependency to be installed to keep our library "modular" and self contained. In other words, we just want to install our library and automatically get all the dependencies that it needs.



      We do not want to rely on the warning message from a peerDependencies.



      It seems like this has to be a possible pattern, can anyone explain the point of bundledDependencies







      angular npm angular-material angular-cli






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 20:05







      JBoothUA

















      asked Nov 13 '18 at 20:34









      JBoothUAJBoothUA

      875425




      875425
























          1 Answer
          1






          active

          oldest

          votes


















          3














          bundledDependencies is used to specify packages that you are including in your package. If you use that then you have to provide those packages in your bundle. They are distributed and installed as part of your package, not as separate dependency installations. See :http://npm.github.io/using-pkgs-docs/package-json/types/bundleddependencies.html.



          An alternative, and I think the correct approach for libraries, is to use peerDependencies (that's what I use). This lets the library user decide whether or not they want to install those packages via their application's package.json, and will warn about "unmet peer dependencies" when installing your package but won't install them. This is useful because it allows the user to control the version of the dependent package. Angular Material specifies all of the various @angular dependencies that it requires as peerDependencies (see https://github.com/angular/material2/blob/master/src/lib/package.json).



          If you want to force a dependency to be installed when your package is installed, just use dependencies. I believe this is generally not recommended for libraries.






          share|improve this answer


























          • Thanks! this is helpful, but I could use a little more information. 1) how do I "provide those packages in your bundle". it is installed in my library. but i only want to install it to that library not everything that USES that library. which sounds like what peerDependencies does, it just adds a warning message?? I think we would like to force the dependency to be installed to keep our library "modular" and self contained. in other words we just want to install our library and automatically get all the dependencies. I think the warning message from a peerDependencies would be a plan b

            – JBoothUA
            Nov 13 '18 at 21:24






          • 1





            Force install == 'dependencies'; provide == 'bundledDependencies' (see the link - that's as much as I know); require install == 'peerDependencies' - this really is what you want. Unfortunately, you can't 'force' a peer-dependency (but the application won't work), so you would have to use 'dependencies' to force installation. But as I said, that's generally not how libraries are done. The warning, and your library documentation, are meant to enforce the dependency requirements.

            – G. Tranter
            Nov 13 '18 at 21:34











          • for any other readers, you were super correct, your last statement is what helped me the most. I had the dependencies in the outer app package.json, but not within the LIBRARY's smaller package.json with the peer dependecies. I have never seen regular dependencies in that file, as you said it may not be the normal pattern, but this is what we are looking for. So in the LIBRARY's package.json you can add regular dependencies!! thank you so much!!!!!

            – JBoothUA
            Nov 14 '18 at 20:11











          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%2f53289082%2fhow-to-bundle-include-dependencies-in-angular-cli-libraries%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          bundledDependencies is used to specify packages that you are including in your package. If you use that then you have to provide those packages in your bundle. They are distributed and installed as part of your package, not as separate dependency installations. See :http://npm.github.io/using-pkgs-docs/package-json/types/bundleddependencies.html.



          An alternative, and I think the correct approach for libraries, is to use peerDependencies (that's what I use). This lets the library user decide whether or not they want to install those packages via their application's package.json, and will warn about "unmet peer dependencies" when installing your package but won't install them. This is useful because it allows the user to control the version of the dependent package. Angular Material specifies all of the various @angular dependencies that it requires as peerDependencies (see https://github.com/angular/material2/blob/master/src/lib/package.json).



          If you want to force a dependency to be installed when your package is installed, just use dependencies. I believe this is generally not recommended for libraries.






          share|improve this answer


























          • Thanks! this is helpful, but I could use a little more information. 1) how do I "provide those packages in your bundle". it is installed in my library. but i only want to install it to that library not everything that USES that library. which sounds like what peerDependencies does, it just adds a warning message?? I think we would like to force the dependency to be installed to keep our library "modular" and self contained. in other words we just want to install our library and automatically get all the dependencies. I think the warning message from a peerDependencies would be a plan b

            – JBoothUA
            Nov 13 '18 at 21:24






          • 1





            Force install == 'dependencies'; provide == 'bundledDependencies' (see the link - that's as much as I know); require install == 'peerDependencies' - this really is what you want. Unfortunately, you can't 'force' a peer-dependency (but the application won't work), so you would have to use 'dependencies' to force installation. But as I said, that's generally not how libraries are done. The warning, and your library documentation, are meant to enforce the dependency requirements.

            – G. Tranter
            Nov 13 '18 at 21:34











          • for any other readers, you were super correct, your last statement is what helped me the most. I had the dependencies in the outer app package.json, but not within the LIBRARY's smaller package.json with the peer dependecies. I have never seen regular dependencies in that file, as you said it may not be the normal pattern, but this is what we are looking for. So in the LIBRARY's package.json you can add regular dependencies!! thank you so much!!!!!

            – JBoothUA
            Nov 14 '18 at 20:11
















          3














          bundledDependencies is used to specify packages that you are including in your package. If you use that then you have to provide those packages in your bundle. They are distributed and installed as part of your package, not as separate dependency installations. See :http://npm.github.io/using-pkgs-docs/package-json/types/bundleddependencies.html.



          An alternative, and I think the correct approach for libraries, is to use peerDependencies (that's what I use). This lets the library user decide whether or not they want to install those packages via their application's package.json, and will warn about "unmet peer dependencies" when installing your package but won't install them. This is useful because it allows the user to control the version of the dependent package. Angular Material specifies all of the various @angular dependencies that it requires as peerDependencies (see https://github.com/angular/material2/blob/master/src/lib/package.json).



          If you want to force a dependency to be installed when your package is installed, just use dependencies. I believe this is generally not recommended for libraries.






          share|improve this answer


























          • Thanks! this is helpful, but I could use a little more information. 1) how do I "provide those packages in your bundle". it is installed in my library. but i only want to install it to that library not everything that USES that library. which sounds like what peerDependencies does, it just adds a warning message?? I think we would like to force the dependency to be installed to keep our library "modular" and self contained. in other words we just want to install our library and automatically get all the dependencies. I think the warning message from a peerDependencies would be a plan b

            – JBoothUA
            Nov 13 '18 at 21:24






          • 1





            Force install == 'dependencies'; provide == 'bundledDependencies' (see the link - that's as much as I know); require install == 'peerDependencies' - this really is what you want. Unfortunately, you can't 'force' a peer-dependency (but the application won't work), so you would have to use 'dependencies' to force installation. But as I said, that's generally not how libraries are done. The warning, and your library documentation, are meant to enforce the dependency requirements.

            – G. Tranter
            Nov 13 '18 at 21:34











          • for any other readers, you were super correct, your last statement is what helped me the most. I had the dependencies in the outer app package.json, but not within the LIBRARY's smaller package.json with the peer dependecies. I have never seen regular dependencies in that file, as you said it may not be the normal pattern, but this is what we are looking for. So in the LIBRARY's package.json you can add regular dependencies!! thank you so much!!!!!

            – JBoothUA
            Nov 14 '18 at 20:11














          3












          3








          3







          bundledDependencies is used to specify packages that you are including in your package. If you use that then you have to provide those packages in your bundle. They are distributed and installed as part of your package, not as separate dependency installations. See :http://npm.github.io/using-pkgs-docs/package-json/types/bundleddependencies.html.



          An alternative, and I think the correct approach for libraries, is to use peerDependencies (that's what I use). This lets the library user decide whether or not they want to install those packages via their application's package.json, and will warn about "unmet peer dependencies" when installing your package but won't install them. This is useful because it allows the user to control the version of the dependent package. Angular Material specifies all of the various @angular dependencies that it requires as peerDependencies (see https://github.com/angular/material2/blob/master/src/lib/package.json).



          If you want to force a dependency to be installed when your package is installed, just use dependencies. I believe this is generally not recommended for libraries.






          share|improve this answer















          bundledDependencies is used to specify packages that you are including in your package. If you use that then you have to provide those packages in your bundle. They are distributed and installed as part of your package, not as separate dependency installations. See :http://npm.github.io/using-pkgs-docs/package-json/types/bundleddependencies.html.



          An alternative, and I think the correct approach for libraries, is to use peerDependencies (that's what I use). This lets the library user decide whether or not they want to install those packages via their application's package.json, and will warn about "unmet peer dependencies" when installing your package but won't install them. This is useful because it allows the user to control the version of the dependent package. Angular Material specifies all of the various @angular dependencies that it requires as peerDependencies (see https://github.com/angular/material2/blob/master/src/lib/package.json).



          If you want to force a dependency to be installed when your package is installed, just use dependencies. I believe this is generally not recommended for libraries.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 21:35

























          answered Nov 13 '18 at 21:11









          G. TranterG. Tranter

          4,4611423




          4,4611423













          • Thanks! this is helpful, but I could use a little more information. 1) how do I "provide those packages in your bundle". it is installed in my library. but i only want to install it to that library not everything that USES that library. which sounds like what peerDependencies does, it just adds a warning message?? I think we would like to force the dependency to be installed to keep our library "modular" and self contained. in other words we just want to install our library and automatically get all the dependencies. I think the warning message from a peerDependencies would be a plan b

            – JBoothUA
            Nov 13 '18 at 21:24






          • 1





            Force install == 'dependencies'; provide == 'bundledDependencies' (see the link - that's as much as I know); require install == 'peerDependencies' - this really is what you want. Unfortunately, you can't 'force' a peer-dependency (but the application won't work), so you would have to use 'dependencies' to force installation. But as I said, that's generally not how libraries are done. The warning, and your library documentation, are meant to enforce the dependency requirements.

            – G. Tranter
            Nov 13 '18 at 21:34











          • for any other readers, you were super correct, your last statement is what helped me the most. I had the dependencies in the outer app package.json, but not within the LIBRARY's smaller package.json with the peer dependecies. I have never seen regular dependencies in that file, as you said it may not be the normal pattern, but this is what we are looking for. So in the LIBRARY's package.json you can add regular dependencies!! thank you so much!!!!!

            – JBoothUA
            Nov 14 '18 at 20:11



















          • Thanks! this is helpful, but I could use a little more information. 1) how do I "provide those packages in your bundle". it is installed in my library. but i only want to install it to that library not everything that USES that library. which sounds like what peerDependencies does, it just adds a warning message?? I think we would like to force the dependency to be installed to keep our library "modular" and self contained. in other words we just want to install our library and automatically get all the dependencies. I think the warning message from a peerDependencies would be a plan b

            – JBoothUA
            Nov 13 '18 at 21:24






          • 1





            Force install == 'dependencies'; provide == 'bundledDependencies' (see the link - that's as much as I know); require install == 'peerDependencies' - this really is what you want. Unfortunately, you can't 'force' a peer-dependency (but the application won't work), so you would have to use 'dependencies' to force installation. But as I said, that's generally not how libraries are done. The warning, and your library documentation, are meant to enforce the dependency requirements.

            – G. Tranter
            Nov 13 '18 at 21:34











          • for any other readers, you were super correct, your last statement is what helped me the most. I had the dependencies in the outer app package.json, but not within the LIBRARY's smaller package.json with the peer dependecies. I have never seen regular dependencies in that file, as you said it may not be the normal pattern, but this is what we are looking for. So in the LIBRARY's package.json you can add regular dependencies!! thank you so much!!!!!

            – JBoothUA
            Nov 14 '18 at 20:11

















          Thanks! this is helpful, but I could use a little more information. 1) how do I "provide those packages in your bundle". it is installed in my library. but i only want to install it to that library not everything that USES that library. which sounds like what peerDependencies does, it just adds a warning message?? I think we would like to force the dependency to be installed to keep our library "modular" and self contained. in other words we just want to install our library and automatically get all the dependencies. I think the warning message from a peerDependencies would be a plan b

          – JBoothUA
          Nov 13 '18 at 21:24





          Thanks! this is helpful, but I could use a little more information. 1) how do I "provide those packages in your bundle". it is installed in my library. but i only want to install it to that library not everything that USES that library. which sounds like what peerDependencies does, it just adds a warning message?? I think we would like to force the dependency to be installed to keep our library "modular" and self contained. in other words we just want to install our library and automatically get all the dependencies. I think the warning message from a peerDependencies would be a plan b

          – JBoothUA
          Nov 13 '18 at 21:24




          1




          1





          Force install == 'dependencies'; provide == 'bundledDependencies' (see the link - that's as much as I know); require install == 'peerDependencies' - this really is what you want. Unfortunately, you can't 'force' a peer-dependency (but the application won't work), so you would have to use 'dependencies' to force installation. But as I said, that's generally not how libraries are done. The warning, and your library documentation, are meant to enforce the dependency requirements.

          – G. Tranter
          Nov 13 '18 at 21:34





          Force install == 'dependencies'; provide == 'bundledDependencies' (see the link - that's as much as I know); require install == 'peerDependencies' - this really is what you want. Unfortunately, you can't 'force' a peer-dependency (but the application won't work), so you would have to use 'dependencies' to force installation. But as I said, that's generally not how libraries are done. The warning, and your library documentation, are meant to enforce the dependency requirements.

          – G. Tranter
          Nov 13 '18 at 21:34













          for any other readers, you were super correct, your last statement is what helped me the most. I had the dependencies in the outer app package.json, but not within the LIBRARY's smaller package.json with the peer dependecies. I have never seen regular dependencies in that file, as you said it may not be the normal pattern, but this is what we are looking for. So in the LIBRARY's package.json you can add regular dependencies!! thank you so much!!!!!

          – JBoothUA
          Nov 14 '18 at 20:11





          for any other readers, you were super correct, your last statement is what helped me the most. I had the dependencies in the outer app package.json, but not within the LIBRARY's smaller package.json with the peer dependecies. I have never seen regular dependencies in that file, as you said it may not be the normal pattern, but this is what we are looking for. So in the LIBRARY's package.json you can add regular dependencies!! thank you so much!!!!!

          – JBoothUA
          Nov 14 '18 at 20:11


















          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%2f53289082%2fhow-to-bundle-include-dependencies-in-angular-cli-libraries%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







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues