Angular:Unable to detect a typescript artifact from another angular library












1















I have made an angular library(A). I started with 'ng generate' command.



So it created classes for me inside lib folder. I put my implementation in these classes. Apart from these auto generated classes, I created two more folders in lib. One contains my service classes(@Injectable) and another one(named 'model') contains my data classes(contained in file model.ts) which are plain ts class.



So for these data classes, folder structure is:




lib/model/model.ts




In app.module.ts, I put these classes (except data classes) under appropriate groups like imports,providers etc.



Now I am using A in a angular project, say 'my-current-angular-project'. I have added dependency in package.json, and added library in node_modules.



In this project,I do:



import {X, Y} from 'A/lib/model/model';


where X,Y are the data classes I have defined in model.ts in A(/lib/model/model.ts).



But when I do 'ng build' for this project, I get error:




ERROR in ./src/app/app.component.ts



Module not found: Error: Can't resolve 'A/lib/model/model' in 'D:projectsmy-current-angular-projectsrcapp'




What mistake am I making here?










share|improve this question





























    1















    I have made an angular library(A). I started with 'ng generate' command.



    So it created classes for me inside lib folder. I put my implementation in these classes. Apart from these auto generated classes, I created two more folders in lib. One contains my service classes(@Injectable) and another one(named 'model') contains my data classes(contained in file model.ts) which are plain ts class.



    So for these data classes, folder structure is:




    lib/model/model.ts




    In app.module.ts, I put these classes (except data classes) under appropriate groups like imports,providers etc.



    Now I am using A in a angular project, say 'my-current-angular-project'. I have added dependency in package.json, and added library in node_modules.



    In this project,I do:



    import {X, Y} from 'A/lib/model/model';


    where X,Y are the data classes I have defined in model.ts in A(/lib/model/model.ts).



    But when I do 'ng build' for this project, I get error:




    ERROR in ./src/app/app.component.ts



    Module not found: Error: Can't resolve 'A/lib/model/model' in 'D:projectsmy-current-angular-projectsrcapp'




    What mistake am I making here?










    share|improve this question



























      1












      1








      1








      I have made an angular library(A). I started with 'ng generate' command.



      So it created classes for me inside lib folder. I put my implementation in these classes. Apart from these auto generated classes, I created two more folders in lib. One contains my service classes(@Injectable) and another one(named 'model') contains my data classes(contained in file model.ts) which are plain ts class.



      So for these data classes, folder structure is:




      lib/model/model.ts




      In app.module.ts, I put these classes (except data classes) under appropriate groups like imports,providers etc.



      Now I am using A in a angular project, say 'my-current-angular-project'. I have added dependency in package.json, and added library in node_modules.



      In this project,I do:



      import {X, Y} from 'A/lib/model/model';


      where X,Y are the data classes I have defined in model.ts in A(/lib/model/model.ts).



      But when I do 'ng build' for this project, I get error:




      ERROR in ./src/app/app.component.ts



      Module not found: Error: Can't resolve 'A/lib/model/model' in 'D:projectsmy-current-angular-projectsrcapp'




      What mistake am I making here?










      share|improve this question
















      I have made an angular library(A). I started with 'ng generate' command.



      So it created classes for me inside lib folder. I put my implementation in these classes. Apart from these auto generated classes, I created two more folders in lib. One contains my service classes(@Injectable) and another one(named 'model') contains my data classes(contained in file model.ts) which are plain ts class.



      So for these data classes, folder structure is:




      lib/model/model.ts




      In app.module.ts, I put these classes (except data classes) under appropriate groups like imports,providers etc.



      Now I am using A in a angular project, say 'my-current-angular-project'. I have added dependency in package.json, and added library in node_modules.



      In this project,I do:



      import {X, Y} from 'A/lib/model/model';


      where X,Y are the data classes I have defined in model.ts in A(/lib/model/model.ts).



      But when I do 'ng build' for this project, I get error:




      ERROR in ./src/app/app.component.ts



      Module not found: Error: Can't resolve 'A/lib/model/model' in 'D:projectsmy-current-angular-projectsrcapp'




      What mistake am I making here?







      angular typescript






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '18 at 15:21







      Mapper

















      asked Nov 27 '18 at 15:16









      MapperMapper

      1315




      1315
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I'm not quite sure if I got your folder structure/ question right. However, the following folder structure should work:




          • your root folder of all sources my-current-angular-projectsrc

          • in this folder you can place your data classes like my-current-angular-projectsrcmy_data_class.ts where you define the export class Data { ... for example

          • now let's assume you have generated a component with angular cli like my-component

          • you now have a folder my-current-angular-projectsrcmy-component that comprises the file my-component.component.ts

          • in this file (my-component.component.ts) you can now use your dataclass like this: import {Data } from '../my_data_class';


          Note: in this case there is no need to specify/include my_data_class.ts in angular.json or somewhere else






          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%2f53502706%2fangularunable-to-detect-a-typescript-artifact-from-another-angular-library%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









            0














            I'm not quite sure if I got your folder structure/ question right. However, the following folder structure should work:




            • your root folder of all sources my-current-angular-projectsrc

            • in this folder you can place your data classes like my-current-angular-projectsrcmy_data_class.ts where you define the export class Data { ... for example

            • now let's assume you have generated a component with angular cli like my-component

            • you now have a folder my-current-angular-projectsrcmy-component that comprises the file my-component.component.ts

            • in this file (my-component.component.ts) you can now use your dataclass like this: import {Data } from '../my_data_class';


            Note: in this case there is no need to specify/include my_data_class.ts in angular.json or somewhere else






            share|improve this answer




























              0














              I'm not quite sure if I got your folder structure/ question right. However, the following folder structure should work:




              • your root folder of all sources my-current-angular-projectsrc

              • in this folder you can place your data classes like my-current-angular-projectsrcmy_data_class.ts where you define the export class Data { ... for example

              • now let's assume you have generated a component with angular cli like my-component

              • you now have a folder my-current-angular-projectsrcmy-component that comprises the file my-component.component.ts

              • in this file (my-component.component.ts) you can now use your dataclass like this: import {Data } from '../my_data_class';


              Note: in this case there is no need to specify/include my_data_class.ts in angular.json or somewhere else






              share|improve this answer


























                0












                0








                0







                I'm not quite sure if I got your folder structure/ question right. However, the following folder structure should work:




                • your root folder of all sources my-current-angular-projectsrc

                • in this folder you can place your data classes like my-current-angular-projectsrcmy_data_class.ts where you define the export class Data { ... for example

                • now let's assume you have generated a component with angular cli like my-component

                • you now have a folder my-current-angular-projectsrcmy-component that comprises the file my-component.component.ts

                • in this file (my-component.component.ts) you can now use your dataclass like this: import {Data } from '../my_data_class';


                Note: in this case there is no need to specify/include my_data_class.ts in angular.json or somewhere else






                share|improve this answer













                I'm not quite sure if I got your folder structure/ question right. However, the following folder structure should work:




                • your root folder of all sources my-current-angular-projectsrc

                • in this folder you can place your data classes like my-current-angular-projectsrcmy_data_class.ts where you define the export class Data { ... for example

                • now let's assume you have generated a component with angular cli like my-component

                • you now have a folder my-current-angular-projectsrcmy-component that comprises the file my-component.component.ts

                • in this file (my-component.component.ts) you can now use your dataclass like this: import {Data } from '../my_data_class';


                Note: in this case there is no need to specify/include my_data_class.ts in angular.json or somewhere else







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 27 '18 at 16:05









                d4rtyd4rty

                1,39821533




                1,39821533
































                    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%2f53502706%2fangularunable-to-detect-a-typescript-artifact-from-another-angular-library%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

                    Lallio

                    Futebolista

                    Jornalista