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?
angular angular7
add a comment |
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?
angular angular7
add a comment |
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?
angular angular7
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
angular angular7
edited Nov 9 at 17:39
Goncalo Peres
8711311
8711311
asked Nov 8 at 13:14
JDS
168214
168214
add a comment |
add a comment |
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 {}
add a comment |
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 {}
add a comment |
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 {}
add a comment |
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 {}
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 {}
answered Nov 8 at 13:51
peinearydevelopment
3,51742046
3,51742046
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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