-
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
environment.dev|prod|etc.ts files don't appear to be copied into environment.ts #2075
Comments
See #2073. It is changed to be only two files by default environment.ts (dev env) and environment.prod.ts (prod env) |
I'm a little confused. If |
Bear in mind that the content will be copied at runtime, in memory for I just tried this on a brand new |
I think I know what's happening. It's the typechecker, it's not using the file replacement. I'll see if it can be fixed. Try this for now: use the same interface in both files aka have the Example:
|
Thanks for looking into it! |
When can we expect a fix for this please? |
@ukaaa @radoslavpetranov What is the use case to have different variables in environment? How do you handle that in code? |
@JiriBalcar to only show information and links when we're running our app in a development environment. |
@ukaaa And for that usecase you can use the production flag which is in both of the files. So you do not need different interface in evironment. Right? |
@JiriBalcar oh yes, definitely. Only that doesn't seem to work either for me using I have the following environments under environment.dev.ts
environment.prod.ts
environment.ts
angular-cli.json
And finally in one of my components let's say I have this: import { environment } from '../../environments/environment'; But when I serve using {
production: false
} Same happens with |
@JiriBalcar my use case is slightly different. I think it makes sense to put all possible config variables in a single file (let's say environment.dev.ts) and then have environment.prod.ts basically import environment.dev.ts and extend it (Object.assign) with only those values we need to set different from defaults. This way all supported config values and their defaults are in one place and in the other file we only change the ones we care about without worrying about adding new config values to both files. For that reason I tried importing environment.dev.ts into environment.prod.ts where I would just extend the defaults in and return the extended environment.dev.ts object. I expected that the end result would end up in environment.ts but then this thread made me realize this is not how it works. All in all at first I thought this is a bug but then I realized that's by design hence my participation in this thread. |
@ukaaa Strange, for me this exact scenario works great. Did you tried that in new project? @radoslavpetranov I beleive it should work if you put your dev config to environment.ts instead of environment.dev.ts as this pull request (#2073). Then you always have full development variables and in prod mode the extend the dev. Did you tried that? |
@JiriBalcar With a new project it seems to work … Very strange. Not sure what I should do now. |
I've just upgraded my existing project to |
@ukaaa Can I look at your repository? |
@JiriBalcar I did a clean install of the project and now everything works. Probably some files remained somewhere they didn't need to be. I remember the environments folder moving around a few versions back, I guess it was related to that. |
I'm having the same problem. On new project is working but on old one is not. Any suggestions? |
@Kosmonaft the environments folder is now on a different location than in earlier versions. Maybe you can compare both projects and their folder structure. |
I have the similar issue, but simple to solve just looking how it works in new created by angular-cli project.
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
} Worked for me. |
My environment.dev|etc.ts files don't appear to be copied into environment.ts when using AoT AND using components that are AoT compiled/imported from another library... I had an auth service class that is injected into a lot of various components throughout my app. It's a singleton defined once in the Core Module (per ng docs example). Previously, the class had an Now, I've just refactored this class to another beta.22 / ng 2.4.1 repository, which serves as a common components library for the x other angular app I'll be writing. It is compiled using ngc so my first (and future) app can import it. Since the service class can no longer depend on a locally imported environment.ts file to inform it of API endpoints, I am instead injecting a config object into the class. (per ng doc's tutorial on DI, OpaqueToken...). This config object is defined in the Core Module instead. And in my Core Module code, I no longer importing auth service locally. This is essentially how it looks:
Works fine so far. Now, I've also refactored out all my auth-related pages, like login, sign-up, reset password pages. These are all packed together into an NgModule and lazy loaded. I successfully refactored it out into the common repo as well: Routes:
app/auth/module.ts:
(in the above file, simply doing an If I serve the app it in normal mode and using the imported pages, the env is set. It is only when I do the import AND use AoT that the env is not set. More specifically, a console.log right before the |
@aaronleeucla I might be seeing the same thing. I have a string provider like this:
And in my constructor, I print out that the value in the environment is different than the one in the injected provider.
This is only during build (which I am doing with AOT). I guess the environment value is being set during compilation prior to the environment being worked out? |
@deebloo @aaronleeucla Thanks. I wasn't aware of useFactory. Worked perfectly. |
hi, |
Can be closed? I believe this was fixed awhile ago |
for me it also happens in 1.0.0-rc.0 but it was fixed for me by adding the missing typings
but: is that really desired / the correct solution? |
Closing as fixed. |
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. |
Ubuntu 16.04
ng --version
. If there's nothing outputted, please runin a Terminal:
node --version
and paste the result here:do on your code? etc.
src/environments/environment
into a component and attempt to use a newly added variable.{ production: bool }
more information.
N/A
Specifically importing environment.dev or environment.prod (as appropriate) works fine, but obviously isn't practical.
The text was updated successfully, but these errors were encountered: