Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng serve does not support the "define" argument #28905

Open
Klaster1 opened this issue Nov 20, 2024 · 4 comments
Open

ng serve does not support the "define" argument #28905

Klaster1 opened this issue Nov 20, 2024 · 4 comments

Comments

@Klaster1
Copy link

Command

serve

Description

I want to pass environment variables into the application during serve and build. In Angular 19, this works for build: ng build --define="GGCC_TARGET='hosted'", while this doesn't for serve: ng serve --define="GGCC_TARGET='hosted'", with the following error:

Error: Unknown argument: define

Describe the solution you'd like

The --define argument works for both serve and build commands.

Describe alternatives you've considered

The custom "@ngx-env/builder:application" builder works, but I'd prefer to keep the amount of extra libraries to a minimum. Given how that builder is merely a thin wrapper around "@angular/build:application", I don't see why this couldn't work as I expect out of the box.

@alan-agius4
Copy link
Collaborator

This behavior is expected since the define configuration is derived from the build section of the angular.json file when executing ng serve.

"architect": {
  "build": {
    "builder": "@angular-devkit/build-angular:application",
    "options": {
      "define": {
        "GGCC_TARGET": "'hosted'"
      },

@alan-agius4 alan-agius4 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2024
@Klaster1
Copy link
Author

Sorry, but I don't get it. Do you suggest to edit the "angular.json" instead of passing an env var, which worked for my team for years?

@alan-agius4
Copy link
Collaborator

Does the value of GGCC_TARGET need to change between various ng serve invocations where its value is set via an environment variable?

@alan-agius4 alan-agius4 added the needs: more info Reporter must clarify the issue label Nov 20, 2024
@alan-agius4 alan-agius4 reopened this Nov 20, 2024
@Klaster1
Copy link
Author

Klaster1 commented Nov 20, 2024

Yes, I pass different values to run the app in different configurations, i.e with some fractures hidden and different brandings.

@alan-agius4 alan-agius4 added feature Issue that requests a new feature devkit/build-angular:dev-server area: @angular/build and removed needs: more info Reporter must clarify the issue labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants