如何解决[重复]的生产构建问题

Posted

技术标签:

【中文标题】如何解决[重复]的生产构建问题【英文标题】:How to solve production build issue of [duplicate] 【发布时间】:2021-04-22 12:02:23 【问题描述】:

我已经创建了我的 Angular 8 应用程序。 在命令 ng serve 应用程序运行顺利,没有任何错误,代码正常工作,但是, 当我为生产创建构建时,我得到了如下所示的错误图像。

我使用 node-rsa 包来加密和解密我的数据,但我无法为生产服务器构建项目,我不知道这些错误是如何引发的。

我的package.json


  "name": "cftrack",
  "version": "0.0.0",
  "scripts": 
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  ,
  "private": true,
  "dependencies": 
    "@angular/animations": "~8.2.14",
    "@angular/cdk": "~8.2.3",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/material": "^8.2.3",
    "@angular/material-moment-adapter": "^8.2.3",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@fortawesome/fontawesome-free": "^5.15.1",
    "@types/jquery": "^3.5.4",
    "angular-animations": "^0.11.0",
    "angular-font-awesome": "^3.1.2",
    "bootstrap": "^4.3.1",
    "bootstrap-select": "^1.13.18",
    "buffer": "^6.0.3",
    "classlist.js": "^1.1.20150312",
    "cors": "^2.8.5",
    "file-saver": "^2.0.5",
    "font-awesome": "^4.7.0",
    "fs": "0.0.1-security",
    "jquery": "^3.5.1",
    "moment": "^2.29.1",
    "ngx-spinner": "^10.0.1",
    "ngx-toastr": "^11.3.3",
    "node-rsa": "^1.1.1",
    "popper.js": "^1.16.1",
    "primeng": "^11.0.0-rc.1",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "uuid": "^8.3.2",
    "web-animations-js": "^2.3.2",
    "zone.js": "~0.9.1"
  ,
  "devDependencies": 
    "@angular-devkit/build-angular": "~0.803.29",
    "@angular/cli": "~8.3.29",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^8.10.66",
    "@types/node-rsa": "^1.0.0",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~7.0.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "^3.4.4"
  ,
  "description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.3.29.",
  "main": "karma.conf.js",
  "author": "Sachin",
  "license": "ISC"

我的 angular.json 文件


    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": 
        "CFTRACK": 
            "projectType": "application",
            "schematics": ,
            "root": "",
            "sourceRoot": "src",
            "prefix": "app",
            "architect": 
                "build": 
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": 
                        "outputPath": "dist/CFTRACK",
                        "index": "src/index.html",
                        "main": "src/main.ts",
                        "polyfills": "src/polyfills.ts",
                        "tsConfig": "tsconfig.app.json",
                        "aot": false,
                        "assets": [
                            "src/favicon.ico",
                            "src/files",
                            "src/assets",
                            "src/web.config"
                        ],
                        "styles": [
                            "src/styles.css",
                            "node_modules/bootstrap/dist/css/bootstrap.min.css",
                            "node_modules/@fortawesome/fontawesome-free/css/v4-shims.min.css",
                            "node_modules/@fortawesome/fontawesome-free/css/all.min.css",
                            "node_modules/bootstrap-select/dist/css/bootstrap-select.min.css",
                            "node_modules/ngx-toastr/toastr.css",
                            "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
                        ],
                        "scripts": [
                            "node_modules/jquery/dist/jquery.slim.min.js",
                            "node_modules/popper.js/dist/umd/popper.js",
                            "node_modules/bootstrap/dist/js/bootstrap.min.js",
                            "node_modules/bootstrap-select/dist/js/bootstrap-select.min.js"
                        ]
                    ,
                    "configurations": 
                        "production": 
                            "fileReplacements": [
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.prod.ts"
                            ],
                            "optimization": true,
                            "outputHashing": "all",
                            "sourceMap": false,
                            "extractCss": true,
                            "namedChunks": false,
                            "aot": true,
                            "extractLicenses": true,
                            "vendorChunk": false,
                            "buildOptimizer": true,
                            "budgets": [
                                    "type": "initial",
                                    "maximumWarning": "10mb",
                                    "maximumError": "10mb"
                                ,
                                
                                    "type": "anyComponentStyle",
                                    "maximumWarning": "10kb",
                                    "maximumError": "15kb"
                                
                            ]
                        
                    
                ,
                "serve": 
                    "builder": "@angular-devkit/build-angular:dev-server",
                    "options": 
                        "browserTarget": "CFTRACK:build"
                    ,
                    "configurations": 
                        "production": 
                            "browserTarget": "CFTRACK:build:production"
                        
                    
                ,
                "extract-i18n": 
                    "builder": "@angular-devkit/build-angular:extract-i18n",
                    "options": 
                        "browserTarget": "CFTRACK: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/files",
                            "src/assets",
                            "src/web.config"
                        ],
                        "styles": [
                            "src/styles.css"
                        ],
                        "scripts": []
                    
                ,
                "lint": 
                    "builder": "@angular-devkit/build-angular:tslint",
                    "options": 
                        "tsConfig": [
                            "tsconfig.app.json",
                            "tsconfig.spec.json",
                            "e2e/tsconfig.json"
                        ],
                        "exclude": [
                            "**/node_modules/**"
                        ]
                    
                ,
                "e2e": 
                    "builder": "@angular-devkit/build-angular:protractor",
                    "options": 
                        "protractorConfig": "e2e/protractor.conf.js",
                        "devServerTarget": "CFTRACK:serve"
                    ,
                    "configurations": 
                        "production": 
                            "devServerTarget": "CFTRACK:serve:production"
                        
                    
                
            
        
    ,
    "defaultProject": "CFTRACK"


在我输入命令“ng build --prod”之后 在这样完成 92% 后它引发了错误

【问题讨论】:

尝试删除你的 node_modules 并运行 npm i。似乎 angular 没有找到 node-rsa 的 nodemodules。 【参考方案1】:

你提到

我已经创建了我的 Angular 10 应用程序

但是 package.json 显示了一个 Angular 8 应用程序???

第一行错误是:node-modules doesn't exist

你确定 npm 包安装成功了吗?

再次使用 npm install 进行检查。

将 angular.json 中的 aot 标志设置为 true,以启用 head of time 编译。

再次服务应用,你一定看到了问题。

对于

Field 'browser' doesn't contain a valid alias configuration

错误见this post

【讨论】:

对不起,先生,我写错了 10 而不是 8。这是一个 Angular 8 应用程序 我删除了 2 次 node-modules 并再次安装它,但仍然出现同样的错误 添加你的 angular.json 文件? 我已经添加了我的 angular.json 文件 检查更新的答案【参考方案2】:

我找到了这些相关问题/错误/错误的答案,

通过添加 package.json

"browser": 
        "path": false,
        "stream": false,
        "tls": false,
        "crypto": false,
        "constants": false
    

更详细的访问下面提到几乎相同的错误答案链接https://***.com/a/52367183/12213901

【讨论】:

以上是关于如何解决[重复]的生产构建问题的主要内容,如果未能解决你的问题,请参考以下文章

如何解决此科尔多瓦构建错误?

如何在开发环境中构建 mdm 解决方案。

MQ如何解决消息的顺序问题和消息的重复问题?

RabbitMQ消息重复消费场景及解决方案

RabbitMQ消息重复消费场景及解决方案

如何解决ios中第3方框架中的重复符号?