首页 > 解决方案 > 错误:TypeError:无法读取未定义的属性“标志”

问题描述

我正在为 Angular 进行迁移,这是之前发布的 package.json:

  "name": "test123",
  "version": "0.0.0",
  "license": "MIT",
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.4.6",
    "@angular/cli": "1.4.1",
    "@angular/common": "^4.4.6",
    "@angular/compiler": "^4.4.6",
    "@angular/compiler-cli": "^4.4.6",
    "@angular/core": "^4.4.6",
    "@angular/forms": "^4.4.6",
    "@angular/http": "^4.4.6",
    "@angular/language-service": "^4.4.6",
    "@angular/platform-browser": "^4.4.6",
    "@angular/platform-browser-dynamic": "^4.4.6",
    "@angular/platform-server": "^4.4.6",
    "@angular/router": "^4.4.6",
    "@jaspero/ng2-confirmations": "^0.3.3",
    "@types/google-maps": "^3.2.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^6.0.90",
    "angular-confirmation-popover": "^3.2.0",
    "angular-font-awesome": "^2.3.7",
    "angular2-datatable-pagination": "git+https://github.com/CasperTech/angular2-datatable-pagination.git",
    "angular2-json2csv": "^1.1.2",
    "angular2-lightbox": "^1.2.1",
    "bootstrap": "^3.3.7",
    "chart.js": "^2.7.1",
    "codelyzer": "~3.1.1",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "jquery": "^3.2.1",
    "jquery-ui-dist": "^1.12.1",
    "karma": "~1.7.0",
    "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",
    "ng-animate": "^0.3.1",
    "ng-pick-datetime": "^5.0.0-beta.11",
    "ng-sweetalert2-slc": "^0.1.7",
    "ng2-archwizard": "^2.1.0",
    "ng2-charts": "^1.6.0",
    "ng2-completer": "^1.6.3",
    "ng2-datetime-picker": "^0.15.1",
    "ng2-map": "^0.16.5",
    "ng2-simple-autocomplete": "^0.6.1",
    "ng2-smart-table": "^1.2.2",
    "ng2-sweetalert2": "0.0.8",
    "ng2-toasty": "^4.0.3",
    "ng2-validation": "^4.2.0",
    "ngx-facebook": "^2.4.0",
    "node-sass": "^4.11.0",
    "popper.js": "^1.12.6",
    "protractor": "~5.1.2",
    "rxjs": "^5.5.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3",
    "zone.js": "^0.8.18"
  },
  "devDependencies": {}
}

这是发布的新 package.json:

{
  "name": "test123",
  "version": "0.0.0",
  "license": "MIT",
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.2.15",
    "@angular/common": "^7.2.15",
    "@angular/compiler": "^7.2.15",
    "@angular/compiler-cli": "^7.2.15",
    "@angular/core": "^7.2.15",
    "@angular/forms": "^7.2.15",
    "@angular/http": "^7.2.15",
    "@angular/language-service": "^7.2.15",
    "@angular/platform-browser": "^7.2.15",
    "@angular/platform-browser-dynamic": "^7.2.15",
    "@angular/platform-server": "^7.2.15",
    "@angular/router": "^7.2.15",
    "@jaspero/ng2-confirmations": "^0.3.3",
    "@types/google-maps": "^3.2.0",
    "@types/jasmine": "~3.3.12",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^12.0.0",
    "angular-confirmation-popover": "^4.2.0",
    "angular-font-awesome": "^3.1.2",
    "angular2-datatable-pagination": "0.0.3",
    "angular2-json2csv": "^1.1.2",
    "angular2-lightbox": "^1.2.1",
    "bootstrap": "^4.3.1",
    "chart.js": "^2.7.1",
    "codelyzer": "~5.0.1",
    "core-js": "^3.0.1",
    "font-awesome": "^4.7.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "jquery": "^3.2.1",
    "jquery-ui-dist": "^1.12.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~2.0.0",
    "karma-coverage-istanbul-reporter": "^2.0.5",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "ng-animate": "^0.3.1",
    "ng-pick-datetime": "^7.0.0",
    "ng-sweetalert2-slc": "^0.1.7",
    "ng2-archwizard": "^2.1.0",
    "ng2-charts": "^2.2.3",
    "ng2-completer": "^2.0.8",
    "ng2-datetime-picker": "^0.15.1",
    "ng2-map": "^0.16.5",
    "ng2-simple-autocomplete": "^0.6.1",
    "ng2-smart-table": "^1.2.2",
    "ng2-sweetalert2": "0.0.8",
    "ng2-toasty": "^4.0.3",
    "ng2-validation": "^4.2.0",
    "ngx-facebook": "^2.4.0",
    "node-sass": "^4.11.0",
    "popper.js": "^1.12.6",
    "protractor": "~5.4.2",
    "rxjs": "^6.5.2",
    "rxjs-compat": "^6.0.0-rc.0",
    "ts-node": "~8.1.0",
    "tslib": "^1.9.0",
    "tslint": "~5.16.0",
    "typescript": "~3.1.6",
    "webpack": "^4.31.0",
    "zone.js": "^0.9.1"
  },
  "devDependencies": {
    "@angular/cli": "^7.3.9",
    "@angular-devkit/build-angular": "~0.13.0"
  }
}

在执行迁移时命令“ng serve”出错:

找不到“AppModule”的 NgModule 元数据中的错误。webpack:编译失败。

甚至在命令“ng build --prod”上发现的错误:

错误:TypeError:无法在 bindChildrenWorker (/home/chaitalimehta) 处读取 checkUnreachable (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:29004:31) 处未定义的属性“标志” /workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:27023:17) 在 bindChildren (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:26979 :17) 在 bindSourceFile (/home/chaitalimehta/workspace/beyou/public/angular/node_modules /typescript/lib/typescript.js:26593:17) 在 Object.bindSourceFile (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:26534:9) 在 Object.createTypeChecker (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:56480:20) 的 initializeTypeChecker (/home/chaitalimehta/workspace/beyou/public/angular/ node_modules/typescript/lib/typescript.js:30758:9) 在 getDiagnosticsProducingTypeChecker (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85043:93) 在 /home/chaitalimehta/工作区/beyou/public/angular/node_modules/typescript/lib/typescript.js:85171:35 at runWithCancellationToken (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85144:24 ) 在 getSemanticDiagnosticsForFileNoCache (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85167:20) 在 getAndCacheDiagnostics (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85415:26) 在 getSemanticDiagnosticsForFile (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/ typescript/lib/typescript.js:85164:20) 在 getDiagnosticsHelper (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85106:24) 在 Object.getSemanticDiagnostics (/home/ chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85119:20)20) 在 getDiagnosticsHelper (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85106:24) 在 Object.getSemanticDiagnostics (/home/chaitalimehta/workspace/beyou/public/angular/ node_modules/typescript/lib/typescript.js:85119:20)20) 在 getDiagnosticsHelper (/home/chaitalimehta/workspace/beyou/public/angular/node_modules/typescript/lib/typescript.js:85106:24) 在 Object.getSemanticDiagnostics (/home/chaitalimehta/workspace/beyou/public/angular/ node_modules/typescript/lib/typescript.js:85119:20)

  1. 尝试清除缓存并重新安装:

    1. rm -rf node_modules dist
    2. npm 缓存清理 --force
    3. // 在 package.json 中添加最新的 typescript
    4. // 删除 package_lock.json
    5. npm 安装
  2. 尝试使用链接从头开始迁移:

    1. https://update.angular.io/
  3. 尝试删除 typescript 然后 tslint 然后 angular-cli

  4. 尝试更改 typescript、tslint、angular-cli 的版本

尝试了很多其他的东西,没有任何解决方案对我有用。

标签: javascripttypescriptangular-cli-v7

解决方案


推荐阅读