angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.76k stars 11.98k forks source link

Object spread in environment files fails for production configuration when used in modules #13413

Closed dougpool closed 5 years ago

dougpool commented 5 years ago

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [X] build
- [X] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

Angular CLI: 7.2.1
Node: 10.15.0
OS: darwin x64
Angular: 7.2.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.1
@angular-devkit/build-angular     0.12.1
@angular-devkit/build-optimizer   0.12.1
@angular-devkit/build-webpack     0.12.1
@angular-devkit/core              7.2.1
@angular-devkit/schematics        7.2.1
@angular/cli                      7.2.1
@ngtools/webpack                  7.2.1
@schematics/angular               7.2.1
@schematics/update                0.12.1
rxjs                              6.3.3
typescript                        3.2.2
webpack                           4.23.1

Repro steps

Step 1: Clone https://github.com/dougpool/aot-prod-env Step 2: ng serve -c dev and check screen/console (works as desired) Step 3: ng serve -c production and check screen/check console (missing common env message is the bug)

The log given by the failure

N/A

Desired functionality

See project README.md for detailed expected output and examples

Environment files composed from other files should work in production mode and have properties copied into environment via the object spread operator and the environment is passed to another module

common-env.ts

export const commonEnv = {
  // Are we running in production mode
  production: false,

  // common mesg
  commonMessage: 'Seen by all envs',
};

environment.prod.ts

import * as common from './common-env';

export const environment = {
  ...common.commonEnv,
  production: true,
  envMessage: 'Prod message',
};

Code where correct environment fails to get created app.module.ts snippet

@NgModule({
  declarations: [AppComponent],
 // env here is not correct
  imports: [BrowserModule, FeatureModuleModule.forRoot(env)],
  providers: [],
  bootstrap: [AppComponent],
})

Instead, the properties are not copied when the the application is served or built with the ng command.

Mention any other details that might be useful

Potentially related: https://github.com/angular/angular-cli/issues/9511

alan-agius4 commented 5 years ago

I think this is by design of the compiler.

Can you open an issue in https://github.com/angular/angular instead?

angular-automatic-lock-bot[bot] commented 5 years ago

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.