-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AOT - incorrect environment #2673
Comments
for those needing a workaround you can use a script to copy the file to environment.ts BEFORE running build and aot. This is the one I use on my CI server. echo "HACK!!!"
__dirname="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cp $__dirname/src/environments/environment.$1.ts $__dirname/src/environments/environment.ts
echo "Copied environment.$2.ts" |
I can confirm this behavior. It only occurs when building with the --aot flag. |
I try this, with success ! export function env() {
return environment;
}
@NgModule({
imports: [
...
],
declarations: [
...
],
providers: [{ provide: AppConfig, useFactory: env }],
bootstrap: [AppComponent]
})
export class AppModule { } |
That is a much better workaround then what I was doing! Solid idea. Totally makes sense as well. |
Experiencing same behaviour, except that workaround only works if AppConfig is within the environment file. Conditionally adding config within other files will not work |
Same issue here. I try to get my firebase config from the environment, but i always receive the default environment file. |
Like @a-legrand mentioned. A workaround right now is to useFactory instead of useValue |
Also experiencing this issue, attempted to use a factory but for some reason the result of the factory wasn't being injected, instead the actual function was. I was most likely doing something wrong but this issue is still the root of it. |
Just want to bump this. I added --aot to our prod build and thus exposed our DEV database to the public. Thankfully there was no big harm this time, but this could potentially have some really serious implications! |
@deebloo I'm having some trouble reproducing this. Can you provide me with a repo where this happens, or tell me what's the definition of |
@filipesilva ill create a small repo with the latest cli |
@filipesilva https://github.com/deebloo/env-error if you look at the console. "production" from directly importing the environment file will be true. "production" when grabbing it from injected service will always be false. |
Fixed by #4475 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
OS?
OSX El Capitan
Versions.
angular-cli: 1.0.0-beta.17
node: 6.7.0
os: darwin x64
Repro steps.
-- create a new app with ng new
-- in src/app/app.module.ts
-- then in the NgModule add
-- run
ng build --prod --aot
If you inject AppConfig into a component or service you will get the incorrect environment.
I am pretty sure aot is breaking the environment switching. when statically analyzing the app module aot pulls in the initial config if passing it to module. The only way I have managed to work around is to copy the file with a script before build.
The text was updated successfully, but these errors were encountered: