I am trying to update my Angular 5.2 app to Angular 6. I successfully followed instructions in the Angular update guide (including the update of angular-cli
to v6), and now I am trying to serve the app via
ng serve --env=local
But this gives me error:
Unknown option: '--env'
I use multiple environments (dev/local/prod
), and this is the way it was working in Angular 5.2. How can I set the environment now in Angular 6?
This question is related to
angular
angular6
angular-cli
Use this command for Angular 6 to build
ng build --prod --configuration=dev
For Angular 2 - 5 refer the article Multiple Environment in angular
For Angular 6 use ng serve --configuration=dev
Note: Refer the same article for angular 6 as well. But wherever you find
--env
instead use--configuration
. That's works well for angular 6.
You can try: ng serve --configuration=dev/prod
To build use: ng build --prod --configuration=dev
Hope you are using a different kind of environment.
You can use command ng serve -c dev
for development environment
ng serve -c prod
for production environment
while building also same applies. You can use ng build -c dev
for dev build
This answer seems good.
however, it lead me towards an error as it resulted with
Configuration 'xyz' could not be found in project ...
error in build.
It is requierd not only to updated build configurations, but also serve
ones.
So just to leave no confusions:
--env
is not supported in angular 6
--env
got changed into --configuration
|| -c
(and is now more powerful)angular.json
file:
{ ... "build": "configurations": ...
propertyfileReplacements
part, (but more options are available){ ... "serve": "configurations": ...
propertybrowserTarget="your-project-name:build:staging"
Angular no longer supports --env instead you have to use
ng serve -c dev
for development environment and,
ng serve -c prod
for production.
NOTE: -c
or --configuration
Source: Stackoverflow.com