angular-cli: Angular CLI v6: "Unknown option: '--environment'"

Versions

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

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.0
@angular-devkit/build-angular     0.6.0
@angular-devkit/build-optimizer   0.6.0
@angular-devkit/core              0.6.0
@angular-devkit/schematics        0.6.0
@ngtools/webpack                  6.0.0
@schematics/angular               0.6.0
@schematics/update                0.6.0
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.7.0

Repro steps

  • Install Angular v6 / CLI v6
  • ng build --environment=foo

Observed behavior

The build --environment CLI option does not work in v6 (or was removed?), however the documentation hasn’t been updated to reflect the new way to build environments?

➜  web git:(ng-v6) ng build --environment=local
Unknown option: '--environment'

ng build --help Does not have any obvious replacement flags or information on how to specify environments during the build.

Desired behavior

Any of:

  • Updated documentation
  • Backwards compatibility (and warnings for deprecated cli flags in prior versions)
  • Fix --environment

Mention any other details that might be useful (optional)

I know Angular CLI is a complicated project, but if you could push one update without breaking every existing project (and project build scripts/CI/CD) that rely on things like --environment= that’d be great, ng update doesn’t seem to address things like this.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 23 (1 by maintainers)

Most upvoted comments

Because of the move to the new angular.json format the environments section is now called configuration within a “project” Just replace --environment with --configuration

It would still be nice to have an alias or warning about deprecated cli flag.s

This is disappointing. Folks, please consider backwards compatibility. Just renaming build parameters without at least deprecation warnings for a while is poor craftsmanship and raises concerns about NG being a first-tier choice.

Same error than @Koesters Configuration ‘prod’ could not be found in project

More information here: https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/application-environments.md

The solution is --configuration=production

yes, the readme file updated 6 days ago is still using --env as example. please fix https://github.com/angular/angular-cli/wiki/build asap.

I arrived here because I, too, was greeted by Unknown option: '--sourcemaps' after updating to Angular 6.

How come none of these breaking changes are documented, neither in the changelog nor in the wiki?

Yeah guys! It wasn’t randomly changed and it throws an error! Who cares if all your builds are suddenly breaking?

To be fair, what other options are there? And it’s a free tool so shrug

ng build --aot --configuration=prod --output-hashing=all --sourcemaps=false --extract-css=true --named-chunks=false --build-optimizer=true

Configuration ‘prod’ could not be found in project ‘sdsd’. Error: Configuration ‘prod’ could not be found in project ‘sdsd’. at Architect.getBuilderConfiguration (C:\sdsd\node_modules@angular-devkit\architect\src\architect.js:106:23) at runSingleTarget (C:\sdsd\node_modules@angular\cli\models\architect-command.js:138:89) at MergeMapSubscriber.rxjs_2.from.pipe.operators_1.concatMap.project (C:\sdsd\node_modules@angular\cli\models\architect-command.js:143:127) at MergeMapSubscriber._tryNext (C:\sdsd\node_modules\rxjs\internal\operators\mergeMap.js:122:27) at MergeMapSubscriber._next (C:\sdsd\node_modules\rxjs\internal\operators\mergeMap.js:112:18) at MergeMapSubscriber.Subscriber.next (C:\sdsd\node_modules\rxjs\internal\Subscriber.js:103:18) at Observable._subscribe (C:\sdsd\node_modules\rxjs\internal\util\subscribeToArray.js:9:20) at Observable._trySubscribe (C:\sdsd\node_modules\rxjs\internal\Observable.js:177:25) at Observable.subscribe (C:\Users\Nils\src\deepship\node_modules\rxjs\internal\Observable.js:162:93) at MergeMapOperator.call (C:\sdsd\node_modules\rxjs\internal\operators\mergeMap.js:87:23)

in environments.ts // The file contents for the current environment will overwrite these during build. // The build system defaults to the dev environment which uses environment.ts, but if you do // ng build --env=prod then environment.prod.ts will be used instead. // The list of which env maps to which file can be found in .angular-cli.json.

ng build --aot --configuration=production --output-hashing=all --sourcemaps=false --extract-css=true --named-chunks=false --build-optimizer=true Unknown option: ‘–sourcemaps’

ng build --aot --configuration=production --output-hashing=all --source-map=false --extract-css=true --named-chunks=false --build-optimizer=true

Sadly the result is defunct as opposed to the same in Angular 5

ng build --aot --configuration=production --output-hashing=all --source-map=true --extract-css=true --named-chunks=false --build-optimizer=true --optimization=false

produces code that works with Cesium and Angular 6.

@rtm You will find the latest documentation on the structure of CLI configuration here.

I’m getting this after upgrading to Angular 6, but I do not have --environment anywhere in my project. Thoughts?

@Koesters With CLI 6, these configuration exist as part of the configuration node like so

"configurations": {
  "production": {
    "fileReplacements": [
      {
        "replace": "src/environments/environment.ts",
        "with": "src/environments/environment.prod.ts"
      }
    ],
    "optimization": true,
    "outputHashing": "all",
    "sourceMap": false,
    "extractCss": true,
    "namedChunks": false,
    "aot": true,
    "extractLicenses": true,
    "vendorChunk": false,
    "buildOptimizer": true
  }

In which case you need not pass them as arguments to the build task. Specifying the --configuration flag with the appropriate environment name should suffice.

This format is actually richer since it allows you specify these commands per environment other than providing different scripting shortcuts for each environment.