Angular 8 ng build --prod 在 TypeError 中发出错误:无法读取未定义的属性“标志”

Posted

技术标签:

【中文标题】Angular 8 ng build --prod 在 TypeError 中发出错误:无法读取未定义的属性“标志”【英文标题】:Angular 8 ng build --prod issue ERROR in TypeError: Cannot read property 'flags' of undefined 【发布时间】:2020-06-17 23:11:02 【问题描述】:

问题 1) 我正在尝试在我最近升级的 Angular 应用程序表单 4.4 到 8 中进行构建 但是面对这个错误,我尝试了网络上所有建议删除节点模块并重新安装的东西,但没有任何帮助。

需要其他帮助:- 此外,您可以看到我安装了很多软件包,如果有人建议如何删除/卸载未使用的软件包,那就太好了。

 ERROR in TypeError: Cannot read property 'flags' of undefined
        at checkUnreachable (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:30043:31)
        at bindChildrenWorker (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:27983:17)
        at bindChildren (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:27939:17)
        at bind (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:29249:21)
        at bindSourceFile (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:27536:17)
        at Object.bindSourceFile (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:27477:9)
        at initializeTypeChecker (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:58859:20)
        at Object.createTypeChecker (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:31761:9)
        at getDiagnosticsProducingTypeChecker (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:88970:93)
        at C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:89097:35
        at runWithCancellationToken (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:89070:24)
        at getSemanticDiagnosticsForFileNoCache (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:89093:20)
        at getAndCacheDiagnostics (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:89341:26)
        at getSemanticDiagnosticsForFile (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:89090:20)
        at getDiagnosticsHelper (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:89032:24)
        at Object.getSemanticDiagnostics (C:\code base\latitude-angular-upgrade-v3\node_modules\typescript\lib\typescript.js:89045:20)

这是我的 package.json 供参考


  "name": "prep-ui",
  "version": "0.18.0",
  "license": "MIT",
  "scripts": 
    "ng": "ng",
    "start": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve",
    "build": "set NODE_OPTIONS=--max_old_space_size=4096 && ng build --prod",
    "build_major": "webpack --env.major",
    "build_minor": "webpack --env.minor",
    "test": "karma start ./karma.conf.js",
    "lint": "ng lint",
    "e2e": "protractor ./protractor.conf.js",
    "pree2e": "webdriver-manager update --standalone false --gecko false --quiet",
    "build_prod_major:prod": "npm run build_major --env.NODE_ENV=production",
    "build:dev": "npm run build_minor --env.NODE_ENV=development",
    "build:prod": "npm run build_minor --env.NODE_ENV=production",
    "build:aws-dev": "npm run build_minor --env.NODE_ENV=aws-dev",
    "build:aws-qa": "npm run build_minor --env.NODE_ENV=aws-qa",
    "build:aws-stg": "npm run build_minor --env.NODE_ENV=aws-stg",
    "build:aws-prep-uat": "npm run build_minor --env.NODE_ENV=aws-prep-uat",
    "build:aws-prod-irmr-dev": "npm run build_minor --env.NODE_ENV=aws-prod-irmr-dev",
    "build:irmr-prod": "npm run build_minor --env.NODE_ENV=irmr-prod",
    "build:irmr-uat": "npm run build_minor --env.NODE_ENV=irmr-uat",
    "build:latitude-dev": "npm run build_minor --env.NODE_ENV=latitude-dev"
  ,
  "private": true,
  "dependencies": 
    "@angular-builders/custom-webpack": "^9.0.0",
    "@angular/animations": "^8.1.1",
    "@angular/cdk": "^8.1.0",
    "@angular/common": "^8.1.1",
    "@angular/compiler": "^8.2.14",
    "@angular/core": "^8.1.1",
    "@angular/flex-layout": "^8.0.0-beta.26",
    "@angular/forms": "^8.1.1",
    "@angular/material": "^8.0.2",
    "@angular/platform-browser": "^8.1.1",
    "@angular/platform-browser-dynamic": "^8.1.1",
    "@angular/platform-server": "^9.0.5",
    "@angular/router": "^8.1.1",
    "@ng-bootstrap/ng-bootstrap": "^5.2.1",
    "@ngtools/webpack": "^1.8.0",
    "@ngx-translate/core": "^11.0.0",
    "@ngx-translate/http-loader": "^4.0.0",
    "@types/highcharts": "5.0.27",
    "@types/jquery": "^3.3.6",
    "@types/jsdom": "^12.2.4",
    "@types/knockout": "^3.4.54",
    "@types/lodash": "^4.14.136",
    "@types/parse5": "^5.0.1",
    "angular-calendar": "^0.28.2",
    "angular-highcharts": "^4.1.0",
    "angular2-http-file-upload": "^1.0.6",
    "bootstrap": "^4.4.1",
    "childnode-remove": "^1.0.1",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.4.1",
    "date-fns": "^2.9.0",
    "file-saver": "^1.3.3",
    "google-libphonenumber": "^3.2.3",
    "hammerjs": "^2.0.8",
    "highcharts": "^8.0.2",
    "highcharts-angular": "^2.4.0",
    "html-loader": "^0.5.5",
    "html-webpack-externals-plugin": "^3.8.0",
    "inputmask": "^4.0.8",
    "intl-tel-input": "^12.1.5",
    "jquery": "^3.4.1",
    "jquery-bar-rating": "^1.2.2",
    "libphonenumber-js": "^0.4.48",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.14",
    "ng-sidebar": "^6.0.2",
    "ng2-completer": "^1.6.3",
    "ng2-nouislider": "^1.7.7",
    "ng2-table": "^1.3.2",
    "ngx-bootstrap": "^5.3.2",
    "ngx-filter-pipe": "^1.0.0",
    "ngx-order-pipe": "^1.0.3",
    "ngx-select-dropdown": "^0.7.0",
    "ngx-select-ex": "^3.5.2-ng4",
    "ngx-webstorage": "^4.0.1",
    "nouislider": "^9.2.0",
    "npm-check-unused": "^6.0.0",
    "print-js": "^1.0.47",
    "rxjs": "^6.5.2",
    "rxjs-compat": "^6.0.0-rc.0",
    "select2": "^4.0.6-rc.1",
    "showdown": "^1.7.5",
    "source-map": "^0.5.7",
    "survey-angular": "^1.0.75",
    "survey-knockout": "^1.0.75",
    "surveyjs-widgets": "^1.0.75",
    "ts-loader": "^6.2.1",
    "tslib": "^1.9.0",
    "webpack": "^4.8.3",
    "webpack-cli": "^3.3.6",
    "webpack-war-plugin": "^1.0.0-beta.3",
    "wnumb": "^1.1.0",
    "zone.js": "~0.9.1"
  ,
  "devDependencies": 
    "@angular-devkit/build-angular": "^0.803.23",
    "@angular/cli": "^8.1.1",
    "@angular/compiler-cli": "^8.1.1",
    "@angular/language-service": "^8.1.1",
    "@ngui/scrollable": "^0.9.1",
    "@types/highcharts": "^5.0.5",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/knockout": "^3.4.53",
    "@types/node": "~6.0.60",
    "autoprefixer": "^6.5.3",
    "circular-dependency-plugin": "^3.0.0",
    "clean-webpack-plugin": "^0.1.16",
    "codelyzer": "^5.0.1",
    "copy-webpack-plugin": "^5.1.1",
    "css-loader": "^3.4.2",
    "cssnano": "^4.1.10",
    "exports-loader": "^0.6.3",
    "file-loader": "^0.10.0",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-typescript": "^0.8.0",
    "html-webpack-plugin": "^3.2.0",
    "istanbul-instrumenter-loader": "^2.0.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "less-loader": "^4.0.5",
    "postcss-loader": "^3.0.0",
    "postcss-url": "^9.0.0",
    "protractor": "^6.0.0",
    "raw-loader": "^0.5.1",
    "sass-loader": "^6.0.3",
    "script-loader": "^0.7.0",
    "source-map-loader": "^0.2.0",
    "style-loader": "^0.13.2",
    "stylus-loader": "^3.0.1",
    "ts-node": "~3.2.0",
    "tslint": "^5.18.0",
    "typescript": "3.4.5",
    "uglifyjs-webpack-plugin": "^0.4.6",
    "webpack": "^4.8.3",
    "webpack-auto-inject-version": "^1.2.2"
  

【问题讨论】:

【参考方案1】:

npm 更新 对我有用,试试就行了

【讨论】:

【参考方案2】:

与其尝试在您自己的代码之外解决这些类型的问题,有时创建一个新的空项目并从旧项目中复制您的源代码会更容易:

创建一个新的空 Angular 8 项目。 将源代码从旧项目复制到新项目。这基本上就是您的/src 目录。 检查您的代码是否有其他依赖项,并使用npm installng add 安装其他软件包。 如果您对任何配置文件进行了手动更改,例如angular.json,您需要相应地修改新项目中的配置文件。我不建议只从旧项目中复制这些文件,因为新版本的 Angular 的结构或内容可能会有所不同。 构建您的项目。

当然,如果 Angular API 发生变化,您仍然会在自己的代码中遇到错误。您需要相应地更改您的代码。

【讨论】:

以上是关于Angular 8 ng build --prod 在 TypeError 中发出错误:无法读取未定义的属性“标志”的主要内容,如果未能解决你的问题,请参考以下文章

Angular 8:运行 ng build --prod --base-href './project1' 时访问资产文件夹

ng build --aot --prod生成文件报错

Angular:仅在 ng build --prod 上构建 ES2015

Angular 8 ng-build 使用科尔多瓦抛出 MIME 错误

在 ng build angular 中运行严格编译

如何在“ng build --prod”之后让我的 Angular 应用程序使用编辑过的配置文件