0

It looks like Vercel is ignoring my Stage environment variables. It just read the Production environment variables. I committed my changes on stage branch and Vercel is deploying it correctly on Preview(stage) environment, but it don't read my variables. If I run the command below in my computer, everything is working fine(I've tried different things):

npm run build -- --configuration stage
npm run build -- --configuration preview

This is my stage environment file

export const environment = {
  production: false,
  API_URL: "https://Ichangedthevaluehere",
  API_LOGIN: "valuechangedhere",
  API_PASSWORD: "valuechangedhere",
  NAME: "Stage",
  VERCEL_GIT_COMMIT_SHA: "",
};

This is my angular.json file

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "thewordsthatiknow": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        },
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/thewordsthatiknow",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss",
              "node_modules/ngx-toastr/toastr.css"
            ],
            "scripts": []
          },
          "configurations": {
            "preview": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.preview.ts"
                }
              ]
            },
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "4kb",
                  "maximumError": "8kb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "preview": {
              "browserTarget": "thewordsthatiknow:build:preview"
            },
            "production": {
              "browserTarget": "thewordsthatiknow:build:production"
            },
            "development": {
              "browserTarget": "thewordsthatiknow:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "thewordsthatiknow:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss",
              "node_modules/ngx-toastr/toastr.css"
            ],
            "scripts": []
          }
        }
      }
    }
  },
  "defaultProject": "thewordsthatiknow"
}

So, do you guys have look to deploy an angular app to Vercel with a stage environment?

Pankwood
  • 1,799
  • 5
  • 24
  • 43

1 Answers1

0

I can't seem to find the stage config in angular.json It should be something like this:

       "configurations": {
            "staging": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.staging.ts"
                }
              ],
              "outputHashing": "all"
            }
}
........

Then on the root of your project create the configuration files e.g. project.stage.json that will tell Vercel which command to use.

{
  "buildCommand": "ng build --configuration staging"
}

And finally, you can build your project via Vercel CLI using:

 vercel deploy --local-config ./project.staging.json
Abdelsalam Shahlol
  • 1,621
  • 1
  • 20
  • 31