发生未处理的异常:\environments\environment.prod.ts 文件替换路径不存在。

7

我将environment.prod.ts文件移动到这个目录'C:\DailyProcess\daily-process\src\WebUI\Angular\src\environments\environment.prod.ts',并且出现了这个错误。我需要帮助并寻求可能的解决方案。以下是我的package.json文件内容。

package.json

{
 "name": "daily-process",
  "version": "0.0.0",
  "scripts": {
   "ng": "ng",
   "start": "ng serve",
   "build": "ng build",
   "watch": "ng build --watch --configuration development",
   "test": "ng test"
    },
  "private": true,
  "dependencies": {
  "@angular/animations": "~13.2.0",
  "@angular/common": "~13.2.0",
  "@angular/compiler": "~13.2.0",
  "@angular/core": "~13.2.0",
   "@angular/forms": "~13.2.0",
  "@angular/platform-browser": "~13.2.0",
  "@angular/platform-browser-dynamic": "~13.2.0",
  "@angular/router": "~13.2.0",
 "rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~13.2.1",
"@angular/cli": "~13.2.1",
"@angular/compiler-cli": "~13.2.0",
"@types/jasmine": "~3.10.0",
"@types/node": "^12.11.1",
  "jasmine-core": "~4.0.0",
  "karma": "~6.3.0",
  "karma-chrome-launcher": "~3.1.0",
  "karma-coverage": "~2.1.0",
   "karma-jasmine": "~4.0.0",
  "karma-jasmine-html-reporter": "~1.7.0",
  "typescript": "~4.5.2"
  }
}

environment.prod.ts

 export const environment = {
 production: true

};

angular.json

 {
   "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
   "version": 1,
   "newProjectRoot": "projects",
   "projects": {
   "daily-process": {
  "projectType": "application",
  "schematics": {},
  "root": "",
  "sourceRoot": "src",
  "prefix": "app",
  "architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "dist/daily-process",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "tsconfig.app.json",
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          "src/styles.css"
        ],
        "scripts": []
      },
      "configurations": {
        "production": {
          "budgets": [
            {
              "type": "initial",
              "maximumWarning": "2mb",
              "maximumError": "5mb"
            },
            {
              "type": "anyComponentStyle",
              "maximumWarning": "6kb",
              "maximumError": "10kb"
            }
          ],
          "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": {
        "production": {
          "browserTarget": "daily-process:build:production"
        },
        "development": {
          "browserTarget": "daily-process:build:development"
        }
      },
      "defaultConfiguration": "development"
    },
    "extract-i18n": {
      "builder": "@angular-devkit/build-angular:extract-i18n",
      "options": {
        "browserTarget": "daily-process: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",
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          "src/styles.css"
        ],
        "scripts": []
        }
      }
    }
  }
},
"defaultProject": "daily-process"
 }

1
请附上您根目录下的 angular.json 文件,因为它包含了文件替换逻辑。 - Joshua McCarthy
放在哪里?是放在这篇帖子里还是我的解决方案里? - lynn0712
是的,请包括您的 angular.json 文件中的代码。至少包括在 configurations > production 中找到的 fileReplacements 属性。 - Joshua McCarthy
我包含了 angular.json 文件。 - lynn0712
我从你分享的代码中没有看到任何可能导致这种情况的问题。我确定你已经检查了实际文件名和目录的拼写,以及angular.json文件是否位于Angular目录中。 - Joshua McCarthy
1
搞定了。我把环境文件放错目录了。一旦我把它们移动到正确的位置,我的构建就成功了。 - lynn0712
2个回答

3

问题已解决。我把环境文件放错目录了,把它们移动到正确的位置后,我的构建成功了。

我把这些文件放在'C:\DailyProcess\daily-process\src\WebUI\Angular\environments\',但实际上应该放在'C:\DailyProcess\daily-process\src\WebUI\Angular\src\environments\'。


0
不小心,我把项目中的environment.development文件删掉了,但是现在我从回收站里恢复了它,现在它正常工作。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接