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

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

Open moloch-- opened this issue 8 years ago • 23 comments

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.

moloch-- avatar May 06 '18 13:05 moloch--

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

ParadoxShmaradox avatar May 06 '18 15:05 ParadoxShmaradox

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

moloch-- avatar May 06 '18 15:05 moloch--

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

BBaysinger avatar May 07 '18 17:05 BBaysinger

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.

zijianhuang avatar May 09 '18 11:05 zijianhuang

@BBaysinger, Do you have --env anywhere? That is an alias for --environment. There is a chance you have that somewhere in the scripts:{ } section of your package.json file.

logic01 avatar May 10 '18 19:05 logic01

@logic01, I don’t have that anywhere either.

BBaysinger avatar May 10 '18 23:05 BBaysinger

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.

Koesters avatar May 12 '18 01:05 Koesters

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

ranouf avatar May 15 '18 19:05 ranouf

and sourcemaps became source-map But the whole command has not the same functionality.

There are also left over by the conversion script. In environment.ts it still refers to "ng build --env=prod" and '.angular-cli.json'

Koesters avatar May 16 '18 09:05 Koesters

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?

codethief avatar May 24 '18 11:05 codethief

Is there a complete, definitive, authoritative, up-to-date definition of the entire syntax and format of angular.json? I for one have not been able to lay my hands on it.

rtm avatar May 25 '18 05:05 rtm

@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.

ekowcharles avatar May 25 '18 11:05 ekowcharles

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

ekowcharles avatar May 25 '18 11:05 ekowcharles

I ended up here with a new install from scratch:

npm -g install @angular/cli
ng new my-app
cd my-app
ng serve -open

Console shows: Unknown option: '-p'.

I am working in an empty directory and uninstalled @angular/cli before starting the new install.

I'm also using Windows 10 and an elevated command prompt.

Edit: If I remove the '-open' the server starts up, and I just have to open the browser myself.

Reboog711 avatar Jun 03 '18 03:06 Reboog711

@Reboog711 -open and --open have different meanings. -open is the equivalent of -o -p -e -n

clydin avatar Jun 04 '18 13:06 clydin

@clydin I had no idea; I was using a single slash w/ the Angular CLI 5 and it worked as expected.

The double slash does indeed address the errors. Thanks!

Reboog711 avatar Jun 05 '18 00:06 Reboog711

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.

johnstsimoes avatar Jun 13 '18 16:06 johnstsimoes

Switching to configuration setup in the angular.json using ng serve -c=prod causes the project to be extremely slow. Like its rebuilding every time I make a change. Is anyone else experiencing this sluggishness?

unstephenk avatar Jul 07 '18 02:07 unstephenk

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

KthProg avatar Aug 23 '18 19:08 KthProg

good issue, thanks

ZQ-jhon avatar Mar 29 '19 11:03 ZQ-jhon