NPM resolve peer dependencies with transitive dependencies












0















I have 3 packages A, B, C, and the i'm developing in requires that package A has B and C as dependecies, but the problem here is that package C also depends on package B, below block describing the case.



enter image description here



So i was thinking of having Package B as peer dependecy inside A,C, but this way it doesn't work, when i tried to run for ex unit test on package A, it always will fail



Start testing for:  /.main.spec.js?/
module.js:549
throw err;
^

Error: Cannot find module 'B/user/model'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (D:workspace1Anode_modules@compClibformcontainer.js:13:14)
at Module._compile (module.js:652:30)
at Module._extensions..js (module.js:663:10)
at Object.require.extensions.(anonymous function) [as .js] (D:workspace1Anode_modulesbabel-registerlibnode.js:152:7)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (D:workspace1Anode_modules@compClibindex.js:12:18)
at Module._compile (module.js:652:30)
at Module._extensions..js (module.js:663:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Exit status 1


Package A package.json file



  "dependencies": {
"@comp/C": "0.0.1"
}
"peerDependencies": {
"@comp/B": "0.0.1"
}


Package C package.json file



  "peerDependencies": {
"@comp/B": "0.0.1"
}


Beside that in Package C, i'm not import B functions from the package directly
like



import X from '@comp/C'


rather i'm using absolute path for the module like:
import X from 'C/X'



and then in webpack i'm using alias for package C,



alias:{
'C': path.resolve(__dirname, './node_modules/@comp/C/lib/app')
}


for local development it works correctly, but if pushed the packages and tried to use them as a single package (package A) it won't work and will give the above npm error.



I'm i doing it right, or is there another way to handle this case?










share|improve this question



























    0















    I have 3 packages A, B, C, and the i'm developing in requires that package A has B and C as dependecies, but the problem here is that package C also depends on package B, below block describing the case.



    enter image description here



    So i was thinking of having Package B as peer dependecy inside A,C, but this way it doesn't work, when i tried to run for ex unit test on package A, it always will fail



    Start testing for:  /.main.spec.js?/
    module.js:549
    throw err;
    ^

    Error: Cannot find module 'B/user/model'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (D:workspace1Anode_modules@compClibformcontainer.js:13:14)
    at Module._compile (module.js:652:30)
    at Module._extensions..js (module.js:663:10)
    at Object.require.extensions.(anonymous function) [as .js] (D:workspace1Anode_modulesbabel-registerlibnode.js:152:7)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (D:workspace1Anode_modules@compClibindex.js:12:18)
    at Module._compile (module.js:652:30)
    at Module._extensions..js (module.js:663:10)
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! Exit status 1


    Package A package.json file



      "dependencies": {
    "@comp/C": "0.0.1"
    }
    "peerDependencies": {
    "@comp/B": "0.0.1"
    }


    Package C package.json file



      "peerDependencies": {
    "@comp/B": "0.0.1"
    }


    Beside that in Package C, i'm not import B functions from the package directly
    like



    import X from '@comp/C'


    rather i'm using absolute path for the module like:
    import X from 'C/X'



    and then in webpack i'm using alias for package C,



    alias:{
    'C': path.resolve(__dirname, './node_modules/@comp/C/lib/app')
    }


    for local development it works correctly, but if pushed the packages and tried to use them as a single package (package A) it won't work and will give the above npm error.



    I'm i doing it right, or is there another way to handle this case?










    share|improve this question

























      0












      0








      0








      I have 3 packages A, B, C, and the i'm developing in requires that package A has B and C as dependecies, but the problem here is that package C also depends on package B, below block describing the case.



      enter image description here



      So i was thinking of having Package B as peer dependecy inside A,C, but this way it doesn't work, when i tried to run for ex unit test on package A, it always will fail



      Start testing for:  /.main.spec.js?/
      module.js:549
      throw err;
      ^

      Error: Cannot find module 'B/user/model'
      at Function.Module._resolveFilename (module.js:547:15)
      at Function.Module._load (module.js:474:25)
      at Module.require (module.js:596:17)
      at require (internal/module.js:11:18)
      at Object.<anonymous> (D:workspace1Anode_modules@compClibformcontainer.js:13:14)
      at Module._compile (module.js:652:30)
      at Module._extensions..js (module.js:663:10)
      at Object.require.extensions.(anonymous function) [as .js] (D:workspace1Anode_modulesbabel-registerlibnode.js:152:7)
      at Module.load (module.js:565:32)
      at tryModuleLoad (module.js:505:12)
      at Function.Module._load (module.js:497:3)
      at Module.require (module.js:596:17)
      at require (internal/module.js:11:18)
      at Object.<anonymous> (D:workspace1Anode_modules@compClibindex.js:12:18)
      at Module._compile (module.js:652:30)
      at Module._extensions..js (module.js:663:10)
      npm ERR! code ELIFECYCLE
      npm ERR! errno 1
      npm ERR! Exit status 1


      Package A package.json file



        "dependencies": {
      "@comp/C": "0.0.1"
      }
      "peerDependencies": {
      "@comp/B": "0.0.1"
      }


      Package C package.json file



        "peerDependencies": {
      "@comp/B": "0.0.1"
      }


      Beside that in Package C, i'm not import B functions from the package directly
      like



      import X from '@comp/C'


      rather i'm using absolute path for the module like:
      import X from 'C/X'



      and then in webpack i'm using alias for package C,



      alias:{
      'C': path.resolve(__dirname, './node_modules/@comp/C/lib/app')
      }


      for local development it works correctly, but if pushed the packages and tried to use them as a single package (package A) it won't work and will give the above npm error.



      I'm i doing it right, or is there another way to handle this case?










      share|improve this question














      I have 3 packages A, B, C, and the i'm developing in requires that package A has B and C as dependecies, but the problem here is that package C also depends on package B, below block describing the case.



      enter image description here



      So i was thinking of having Package B as peer dependecy inside A,C, but this way it doesn't work, when i tried to run for ex unit test on package A, it always will fail



      Start testing for:  /.main.spec.js?/
      module.js:549
      throw err;
      ^

      Error: Cannot find module 'B/user/model'
      at Function.Module._resolveFilename (module.js:547:15)
      at Function.Module._load (module.js:474:25)
      at Module.require (module.js:596:17)
      at require (internal/module.js:11:18)
      at Object.<anonymous> (D:workspace1Anode_modules@compClibformcontainer.js:13:14)
      at Module._compile (module.js:652:30)
      at Module._extensions..js (module.js:663:10)
      at Object.require.extensions.(anonymous function) [as .js] (D:workspace1Anode_modulesbabel-registerlibnode.js:152:7)
      at Module.load (module.js:565:32)
      at tryModuleLoad (module.js:505:12)
      at Function.Module._load (module.js:497:3)
      at Module.require (module.js:596:17)
      at require (internal/module.js:11:18)
      at Object.<anonymous> (D:workspace1Anode_modules@compClibindex.js:12:18)
      at Module._compile (module.js:652:30)
      at Module._extensions..js (module.js:663:10)
      npm ERR! code ELIFECYCLE
      npm ERR! errno 1
      npm ERR! Exit status 1


      Package A package.json file



        "dependencies": {
      "@comp/C": "0.0.1"
      }
      "peerDependencies": {
      "@comp/B": "0.0.1"
      }


      Package C package.json file



        "peerDependencies": {
      "@comp/B": "0.0.1"
      }


      Beside that in Package C, i'm not import B functions from the package directly
      like



      import X from '@comp/C'


      rather i'm using absolute path for the module like:
      import X from 'C/X'



      and then in webpack i'm using alias for package C,



      alias:{
      'C': path.resolve(__dirname, './node_modules/@comp/C/lib/app')
      }


      for local development it works correctly, but if pushed the packages and tried to use them as a single package (package A) it won't work and will give the above npm error.



      I'm i doing it right, or is there another way to handle this case?







      npm webpack dependencies peer-dependencies






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 23:39









      M1M6M1M6

      1802318




      1802318
























          0






          active

          oldest

          votes











          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%2f53384209%2fnpm-resolve-peer-dependencies-with-transitive-dependencies%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f53384209%2fnpm-resolve-peer-dependencies-with-transitive-dependencies%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

          MongoDB - Not Authorized To Execute Command

          Npm cannot find a required file even through it is in the searched directory

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith