Angular 6找不到环境变量

时间:2019-12-29 11:19:48

标签: angular environment-variables angular6

我们有两个不同的工作组。一个是开发人员,另一个是数据科学家。我们的开发人员正在本地服务器上工作,而数据科学家正在另一台服务器上工作。

因此,我为它们创建了一个环境文件。

//path: src/environments
//fileName: environment.dataScience.ts

export const environment = {
  production: false,
  backEndServer: 'url for data scientist'

};

和environment.ts看起来像这样:

//path: src/environments
//fileName: environment.ts

export const environment = {
  production: false,
  backEndServer:"local server"
};

现在在vs代码中,当我尝试导入环境文件并且其后端服务器智能无法正常工作时。

enter image description here

ng serve --configuration=dataScience之外也无法正常工作。甚至ng build --configuration=dataScience也不起作用。 我遇到以下错误:error TS2503: Cannot find namespace 'environment'.

这是我在angular.json中配置的方式:

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


      }
    },
    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "angular:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "angular:build:production"
        },
        "dataScience": {
          "browserTarget": "angular:build:dataScience"
        }

我不确定我犯了什么错误。你能帮我么?

0 个答案:

没有答案