angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Incorrect environment file being loaded with ng serve?

Open doovers opened this issue 8 years ago • 4 comments

Versions

Angular CLI: 6.0.0-rc.8
Node: 10.0.0
OS: darwin x64
Angular: 6.0.0-rc.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.5.11
@angular-devkit/build-angular     0.5.11
@angular-devkit/build-optimizer   0.5.11
@angular-devkit/core              0.5.11
@angular-devkit/schematics        0.5.11
@angular/cli                      6.0.0-rc.8
@ngtools/webpack                  6.0.0-rc.9
@schematics/angular               0.5.11
@schematics/update                0.5.11
rxjs                              6.0.0
typescript                        2.7.2
webpack                           4.6.0

Repro steps

ng new temp

Add console.log(environment.production); to app.component.ts

ng serve

Observed behavior

true is logged to console

Desired behavior

false is logged to console

Perhaps my expectations are incorrect here but I would have expected the default behavior for ng serve would be to load the environment.ts file but instead it is loading the environment.prod.ts file. I would expect the latter to be loaded with ng serve --prod. Is this a bug or is this by design? If it is by design, how can I load environment.ts?

doovers avatar May 01 '18 20:05 doovers

Heya, I tried reproducing this with rc.8 and could not. I added the code below to src/app/app.component.ts:

import { environment } from '../environments/environment';
console.log(environment.production);

Then I ran ng serve and saw false being logged: image

If you have a specific project where this happens, can you push it to github please?

filipesilva avatar May 01 '18 21:05 filipesilva

Doh! Well, that's embarrassing! I reopened the project and realized that the auto import in VS code had imported environment.prod. I've no idea how I could have missed that. Apologies for wasting your time!

doovers avatar May 01 '18 21:05 doovers

Had the same problem, VS code's auto-import seems to be the tool of the devil.

wouterhendriks avatar Aug 16 '18 19:08 wouterhendriks

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.