Angular Library - 'rootDir' is expected to contain all source files. (environment.ts)











up vote
0
down vote

favorite












I was working on my first Angular 7 library, however I am getting the this error when trying to compile the library.



Error: error TS6059: File '...environment.ts' is not under 'rootDir' 'my-angular-libraryprojectsmy-librarysrc'. 'rootDir' is expected to contain all source files.



Looking at my tree I have:



-projects
-my-library
-src
-src
- environments


In my class I have the following import:



import { environment } from "src/environments/environment";


I was checking other threads where they mentioned bugs in typescript, however I am running the latest version "typescript": "~3.1.1".



Other threads mentioned about a misconfigured rootDir. I checked my project and I do not have rootDir defined in any of the config files.



I don't need to add an environment to the projects do I?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I was working on my first Angular 7 library, however I am getting the this error when trying to compile the library.



    Error: error TS6059: File '...environment.ts' is not under 'rootDir' 'my-angular-libraryprojectsmy-librarysrc'. 'rootDir' is expected to contain all source files.



    Looking at my tree I have:



    -projects
    -my-library
    -src
    -src
    - environments


    In my class I have the following import:



    import { environment } from "src/environments/environment";


    I was checking other threads where they mentioned bugs in typescript, however I am running the latest version "typescript": "~3.1.1".



    Other threads mentioned about a misconfigured rootDir. I checked my project and I do not have rootDir defined in any of the config files.



    I don't need to add an environment to the projects do I?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I was working on my first Angular 7 library, however I am getting the this error when trying to compile the library.



      Error: error TS6059: File '...environment.ts' is not under 'rootDir' 'my-angular-libraryprojectsmy-librarysrc'. 'rootDir' is expected to contain all source files.



      Looking at my tree I have:



      -projects
      -my-library
      -src
      -src
      - environments


      In my class I have the following import:



      import { environment } from "src/environments/environment";


      I was checking other threads where they mentioned bugs in typescript, however I am running the latest version "typescript": "~3.1.1".



      Other threads mentioned about a misconfigured rootDir. I checked my project and I do not have rootDir defined in any of the config files.



      I don't need to add an environment to the projects do I?










      share|improve this question















      I was working on my first Angular 7 library, however I am getting the this error when trying to compile the library.



      Error: error TS6059: File '...environment.ts' is not under 'rootDir' 'my-angular-libraryprojectsmy-librarysrc'. 'rootDir' is expected to contain all source files.



      Looking at my tree I have:



      -projects
      -my-library
      -src
      -src
      - environments


      In my class I have the following import:



      import { environment } from "src/environments/environment";


      I was checking other threads where they mentioned bugs in typescript, however I am running the latest version "typescript": "~3.1.1".



      Other threads mentioned about a misconfigured rootDir. I checked my project and I do not have rootDir defined in any of the config files.



      I don't need to add an environment to the projects do I?







      angular angular7






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 17:39









      Goncalo Peres

      8711311




      8711311










      asked Nov 8 at 13:14









      JDS

      168214




      168214
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          All files referenced by the library need to be contained within projectmy-librarysrc directory(or pulled in from another module) in order for the library to build properly.



          I don't think you would want to include an environment file directly in your library either. During the build of the application, that environment file would be switched out in the application. With a library though, you build it and then import it into your application already built, so that file won't be switched out appropriately.



          The best solution I'm aware of is to create a Token in your library and export that from the api of the library. Then in the application using the library, you would provide the environment through the DI container utilizing that token.



          For example, in your library, you would do something like the following:



          projectmy-librarysrclibenvironment-token.ts



          import { InjectionToken } from '@angular/core';

          export let ENVIRONMENT_TOKEN = new InjectionToken('environment');


          projectmy-librarysrcpublic_api.ts



          export * from './lib/environment-token.ts'


          projectmy-librarysrclibcomponent.ts



          import {
          Component,
          Inject
          } from '@angular/core';

          import {
          ENVIRONMENT_TOKEN
          } from './environment-token';

          @Component({
          selector: 'aa-component',
          template: `
          })
          export class Component {
          constructor(@Inject(ENVIRONMENT_TOKEN) private environment: any) {
          }
          }


          And then in your application, you would do something like the following:



          import {
          NgModule
          } from '@angular/core';

          import {
          YOUR_MODULE,
          ENVIRONMENT_TOKEN
          } from 'YOUR_LIB_NAME';

          import {
          environment
          } from './environments/environment';

          import {
          AppComponent
          } from './app.component.ts'

          @NgModule({
          declarations: [
          AppComponent
          ],
          imports: [
          YOUR_MODULE
          providers: [
          { provide: ENVIRONMENT_TOKEN, useFactory: () => environment }
          ],
          bootstrap: [AppComponent]
          })
          export class AppModule {}





          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',
            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%2f53208513%2fangular-library-rootdir-is-expected-to-contain-all-source-files-environmen%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








            up vote
            0
            down vote













            All files referenced by the library need to be contained within projectmy-librarysrc directory(or pulled in from another module) in order for the library to build properly.



            I don't think you would want to include an environment file directly in your library either. During the build of the application, that environment file would be switched out in the application. With a library though, you build it and then import it into your application already built, so that file won't be switched out appropriately.



            The best solution I'm aware of is to create a Token in your library and export that from the api of the library. Then in the application using the library, you would provide the environment through the DI container utilizing that token.



            For example, in your library, you would do something like the following:



            projectmy-librarysrclibenvironment-token.ts



            import { InjectionToken } from '@angular/core';

            export let ENVIRONMENT_TOKEN = new InjectionToken('environment');


            projectmy-librarysrcpublic_api.ts



            export * from './lib/environment-token.ts'


            projectmy-librarysrclibcomponent.ts



            import {
            Component,
            Inject
            } from '@angular/core';

            import {
            ENVIRONMENT_TOKEN
            } from './environment-token';

            @Component({
            selector: 'aa-component',
            template: `
            })
            export class Component {
            constructor(@Inject(ENVIRONMENT_TOKEN) private environment: any) {
            }
            }


            And then in your application, you would do something like the following:



            import {
            NgModule
            } from '@angular/core';

            import {
            YOUR_MODULE,
            ENVIRONMENT_TOKEN
            } from 'YOUR_LIB_NAME';

            import {
            environment
            } from './environments/environment';

            import {
            AppComponent
            } from './app.component.ts'

            @NgModule({
            declarations: [
            AppComponent
            ],
            imports: [
            YOUR_MODULE
            providers: [
            { provide: ENVIRONMENT_TOKEN, useFactory: () => environment }
            ],
            bootstrap: [AppComponent]
            })
            export class AppModule {}





            share|improve this answer

























              up vote
              0
              down vote













              All files referenced by the library need to be contained within projectmy-librarysrc directory(or pulled in from another module) in order for the library to build properly.



              I don't think you would want to include an environment file directly in your library either. During the build of the application, that environment file would be switched out in the application. With a library though, you build it and then import it into your application already built, so that file won't be switched out appropriately.



              The best solution I'm aware of is to create a Token in your library and export that from the api of the library. Then in the application using the library, you would provide the environment through the DI container utilizing that token.



              For example, in your library, you would do something like the following:



              projectmy-librarysrclibenvironment-token.ts



              import { InjectionToken } from '@angular/core';

              export let ENVIRONMENT_TOKEN = new InjectionToken('environment');


              projectmy-librarysrcpublic_api.ts



              export * from './lib/environment-token.ts'


              projectmy-librarysrclibcomponent.ts



              import {
              Component,
              Inject
              } from '@angular/core';

              import {
              ENVIRONMENT_TOKEN
              } from './environment-token';

              @Component({
              selector: 'aa-component',
              template: `
              })
              export class Component {
              constructor(@Inject(ENVIRONMENT_TOKEN) private environment: any) {
              }
              }


              And then in your application, you would do something like the following:



              import {
              NgModule
              } from '@angular/core';

              import {
              YOUR_MODULE,
              ENVIRONMENT_TOKEN
              } from 'YOUR_LIB_NAME';

              import {
              environment
              } from './environments/environment';

              import {
              AppComponent
              } from './app.component.ts'

              @NgModule({
              declarations: [
              AppComponent
              ],
              imports: [
              YOUR_MODULE
              providers: [
              { provide: ENVIRONMENT_TOKEN, useFactory: () => environment }
              ],
              bootstrap: [AppComponent]
              })
              export class AppModule {}





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                All files referenced by the library need to be contained within projectmy-librarysrc directory(or pulled in from another module) in order for the library to build properly.



                I don't think you would want to include an environment file directly in your library either. During the build of the application, that environment file would be switched out in the application. With a library though, you build it and then import it into your application already built, so that file won't be switched out appropriately.



                The best solution I'm aware of is to create a Token in your library and export that from the api of the library. Then in the application using the library, you would provide the environment through the DI container utilizing that token.



                For example, in your library, you would do something like the following:



                projectmy-librarysrclibenvironment-token.ts



                import { InjectionToken } from '@angular/core';

                export let ENVIRONMENT_TOKEN = new InjectionToken('environment');


                projectmy-librarysrcpublic_api.ts



                export * from './lib/environment-token.ts'


                projectmy-librarysrclibcomponent.ts



                import {
                Component,
                Inject
                } from '@angular/core';

                import {
                ENVIRONMENT_TOKEN
                } from './environment-token';

                @Component({
                selector: 'aa-component',
                template: `
                })
                export class Component {
                constructor(@Inject(ENVIRONMENT_TOKEN) private environment: any) {
                }
                }


                And then in your application, you would do something like the following:



                import {
                NgModule
                } from '@angular/core';

                import {
                YOUR_MODULE,
                ENVIRONMENT_TOKEN
                } from 'YOUR_LIB_NAME';

                import {
                environment
                } from './environments/environment';

                import {
                AppComponent
                } from './app.component.ts'

                @NgModule({
                declarations: [
                AppComponent
                ],
                imports: [
                YOUR_MODULE
                providers: [
                { provide: ENVIRONMENT_TOKEN, useFactory: () => environment }
                ],
                bootstrap: [AppComponent]
                })
                export class AppModule {}





                share|improve this answer












                All files referenced by the library need to be contained within projectmy-librarysrc directory(or pulled in from another module) in order for the library to build properly.



                I don't think you would want to include an environment file directly in your library either. During the build of the application, that environment file would be switched out in the application. With a library though, you build it and then import it into your application already built, so that file won't be switched out appropriately.



                The best solution I'm aware of is to create a Token in your library and export that from the api of the library. Then in the application using the library, you would provide the environment through the DI container utilizing that token.



                For example, in your library, you would do something like the following:



                projectmy-librarysrclibenvironment-token.ts



                import { InjectionToken } from '@angular/core';

                export let ENVIRONMENT_TOKEN = new InjectionToken('environment');


                projectmy-librarysrcpublic_api.ts



                export * from './lib/environment-token.ts'


                projectmy-librarysrclibcomponent.ts



                import {
                Component,
                Inject
                } from '@angular/core';

                import {
                ENVIRONMENT_TOKEN
                } from './environment-token';

                @Component({
                selector: 'aa-component',
                template: `
                })
                export class Component {
                constructor(@Inject(ENVIRONMENT_TOKEN) private environment: any) {
                }
                }


                And then in your application, you would do something like the following:



                import {
                NgModule
                } from '@angular/core';

                import {
                YOUR_MODULE,
                ENVIRONMENT_TOKEN
                } from 'YOUR_LIB_NAME';

                import {
                environment
                } from './environments/environment';

                import {
                AppComponent
                } from './app.component.ts'

                @NgModule({
                declarations: [
                AppComponent
                ],
                imports: [
                YOUR_MODULE
                providers: [
                { provide: ENVIRONMENT_TOKEN, useFactory: () => environment }
                ],
                bootstrap: [AppComponent]
                })
                export class AppModule {}






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 8 at 13:51









                peinearydevelopment

                3,51742046




                3,51742046






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208513%2fangular-library-rootdir-is-expected-to-contain-all-source-files-environmen%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

                    Schultheiß

                    Verwaltungsgliederung Dänemarks

                    Liste der Kulturdenkmale in Wilsdruff