【问题标题】:Angular TypeError: Object prototype may only be an Object or null: undefinedAngular TypeError:对象原型可能只是一个对象或空:未定义
【发布时间】:2021-02-10 16:30:31
【问题描述】:

在我尝试安装 ExcelJs (npm install --save exceljs) 之前,我有一个工作项目。

之后我开始收到各种错误,例如Cannot read property ‘Minus’ of undefinedCannot find module 'postcss-value-something',无论缺少的部分是什么,npm i 都解决了这些错误。

然而,在此之后,我现在收到TypeError: Object prototype may only be an Object or null: undefined

遇到这些问题后,我删除了 excelJs,希望恢复正常,但没有这样的运气。

完整的错误如下:

    at setPrototypeOf (<anonymous>)
    at Object.__extends (F:\Honeycomb\Honey\Varroa\node_modules\@angular\compiler-cli\node_modules\tslib\tslib.js:68:9)
    at F:\Honeycomb\Honey\Varroa\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:118:17
    at F:\Honeycomb\Honey\Varroa\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:325:6
    at F:\Honeycomb\Honey\Varroa\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:3:17
    at Object.<anonymous> (F:\Honeycomb\Honey\Varroa\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:9:3)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at F:\Honeycomb\Honey\Varroa\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\transform.js:21:22
    at F:\Honeycomb\Honey\Varroa\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\transform.js:10:17
    at Object.<anonymous> (F:\Honeycomb\Honey\Varroa\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\transform.js:16:3)

我的package.json的内容如下:

 "dependencies": {
    "@agm/core": "^1.1.0",
    "@agm/js-marker-clusterer": "^1.0.0-beta.3",
    "@angular/animations": "^8.0.0",
    "@angular/cdk": "^7.3.6",
    "@angular/common": "^8.0.0",
    "@angular/compiler": "^8.0.0",
    "@angular/core": "^8.0.0",
    "@angular/forms": "^8.0.0",
    "@angular/http": "^7.2.16",
    "@angular/material": "^7.3.6",
    "@angular/platform-browser": "^8.0.0",
    "@angular/platform-browser-dynamic": "^8.0.0",
    "@angular/platform-server": "^8.0.0",
    "@angular/router": "^8.0.0",
    "@angular/upgrade": "^8.2.14",
    "@auth0/angular-jwt": "^2.0.0",
    "@types/angular": "^1.6.47",
    "angular-calendar": "^0.28.16",
    "angular2-text-mask": "8.0.4",
    "angular2-toaster": "^8.0.0",
    "animate.css": "^3.7.0",
    "bootstrap": "^4.1.2",
    "brace": "0.11.0",
    "chart.js": "^2.7.3",
    "codemirror": "5.33.0",
    "copy-webpack-plugin": "^4.5.1",
    "core-js": "2.5.3",
    "dragula": "3.7.2",
    "file-saver": "^1.3.8",
    "flag-icon-css": "2.9.0",
    "font-awesome": "^4.7.0",
    "highcharts": "7.0.2",
    "highcharts-angular": "2.4.0",
    "highcharts-boost": "^0.1.7",
    "html2canvas": "^1.0.0-alpha.12",
    "intl": "^1.2.5",
    "js-marker-clusterer": "^1.0.0",
    "jspdf": "^1.5.3",
    "lodash": "^4.17.10",
    "moment": "^2.20.1",
    "ng-mat-select-infinite-scroll": "^2.0.0",
    "ng-select": "^1.0.2",
    "ng2-ace-editor": "^0.3.9",
    "ng2-charts": "1.6.0",
    "ng2-completer": "^3.0.0-beta.2",
    "ng2-dragula": "1.5.0",
    "ng2-file-upload": "1.2.1",
    "ng2-select": "^2.0.0",
    "ng2-validation": "^4.2.0",
    "ngx-bootstrap": "2.0.0-rc.0",
    "ngx-loading": "^8.0.0",
    "ngx-quill": "^8.1.8",
    "normalize.css": "^7.0.0",
    "oidc-client": "^1.5.1",
    "postcss-value-parser": "^4.1.0",
    "primeicons": "4.0.0",
    "primeng": "9.1.0",
    "raven-js": "^3.26.2",
    "rxjs": "6.2.1",
    "rxjs-compat": "^6.2.1",
    "simple-line-icons": "^2.4.1",
    "spinkit": "1.2.5",
    "ts-helpers": "1.1.2",
    "ts-overlapping-marker-spiderfier": "^1.0.2",
    "tslib": "^1.9.0",
    "xlsx": "0.13.3",
    "zone.js": "^0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.803.24",
    "@angular/cli": "^8.3.28",
    "@angular/compiler-cli": "^10.0.2",
    "@angular/language-service": "^10.0.2",
    "@fortawesome/fontawesome-free": "^5.6.1",
    "@types/core-js": "^2.5.3",
    "@types/file-saver": "0.0.1",
    "@types/googlemaps": "3.37.7",
    "@types/highcharts": "5.0.36",
    "@types/jasmine": "^3.5.11",
    "@types/jasminewd2": "2.0.3",
    "@types/jquery": "^3.5.0",
    "@types/lodash": "^4.14.110",
    "@types/luxon": "^1.11.1",
    "@types/node": "^14.0.19",
    "codelyzer": "^6.0.0",
    "jasmine-core": "^3.5.0",
    "jasmine-spec-reporter": "^5.0.2",
    "jasminewd2": "^2.2.0",
    "karma": "^5.1.0",
    "karma-chrome-launcher": "^3.1.0",
    "karma-cli": "^2.0.0",
    "karma-coverage-istanbul-reporter": "1.3.3",
    "karma-jasmine": "^3.3.1",
    "karma-jasmine-html-reporter": "^1.5.4",
    "karma-remap-istanbul": "^0.6.0",
    "protractor": "^7.0.0",
    "rxjs-tslint": "^0.1.8",
    "ts-node": "4.1.0",
    "tslint": "^6.1.2",
    "typescript": "^3.4.5",
    "webpack": "^4.43.0",
    "webpack-bundle-analyzer": "^3.1.0"
  }

到目前为止,我读过的所有地方都表明 cli / 编译器 cli 有问题,但我的印象是 ^ 意味着它会根据需要进行更新,我还尝试删除 ^ 以防版本有超出了我项目支持的 Angular 版本。

ng v 返回以下内容:

Angular CLI: 8.3.28
Node: 10.16.0
OS: win32 x64
Angular: 8.0.0
... animations, common, compiler, core, forms, platform-browser
... platform-browser-dynamic, platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.28
@angular-devkit/build-angular     0.803.28
@angular-devkit/build-optimizer   0.803.28
@angular-devkit/build-webpack     0.803.28
@angular-devkit/core              8.3.28
@angular-devkit/schematics        8.3.28
@angular/cdk                      7.3.7
@angular/cli                      8.3.28
@angular/compiler-cli             10.0.2
@angular/http                     7.2.16
@angular/language-service         10.0.2
@angular/material                 7.3.7
@angular/upgrade                  8.2.14
@ngtools/webpack                  8.3.28
@schematics/angular               8.3.28
@schematics/update                0.803.28
rxjs                              6.2.1
typescript                        3.9.6
webpack                           4.43.0

我怀疑它仍然与编译器/cli 版本甚至打字稿有关,正如我在其他地方看到的那样,但是似乎没有任何关于哪些版本应该与什么一起使用的指南。

非常感谢任何帮助。

【问题讨论】:

    标签: angular typescript exception npm


    【解决方案1】:

    你的角度包版本太不同步了!不知何故,您的编译器 cli 位于 10.0.2,但您的 http 位于 7.2.16。那是怎么发生的?无论如何,升级 Angular 的最佳方法是使用 ng update @angular/cling update @angular/coreng update @angular/material

    这会将其更新到版本 10,并希望进行适当的迁移。无论以 @angular 开头的内容都应该始终具有相同的主要版本。在您的情况下,您将 v7 与 v8 和 v10 混合使用。加入 v9,你就有了一个四重奏。

    如果使用 cli 无法更新,您最好使用以下步骤:

    • 保存您的源代码(位于src 下)以及您可能认为值得保存的任何其他文件,例如package.json,以检查您正在使用的任何非角度包。
    • 删除整个项目文件夹
    • 使用ng -g i @angular/cli@latest 升级您的全局@angular/cli
    • 使用ng new xxx 创建一个新项目
    • 将您的 src 复制到新创建的项目中,但跳过 main.tspolyfills.tstsconfig 文件,因为最新的 angular cli 版本发生了重大变化
    • 可选:使用您可能已经完成的任何自定义更改来更新那些未复制的文件,例如package.json

    从那时起,始终使用ng update 升级任何 Angular 模块,因为这还包括必要的代码迁移。

    附带说明,如果您使用npm update^ 只会更新已安装软件包的次要版本。阅读更多here

    【讨论】:

    • 您好,感谢您的回复,我将开始尝试这些更新。多年来,该项目一直被忽视,并且在任何要求的功能更改方面都做了最低限度的维护。版本不匹配很可能是由于避免了正在使用的旧模块/包的错误。
    • IIRC 我们使用的 agm 与更高版本的 angular 不兼容。
    • @Divine 在这种情况下,您应该恢复到兼容的 Angular 版本,并且永远不要更新 :) 尽管最新的 agm version 确实支持更高的 Angular 版本
    • 我可能需要降级 cli 吗?到 8.X 来匹配其他版本呢?
    猜你喜欢
    • 2019-04-06
    • 2020-10-30
    • 2018-08-06
    • 1970-01-01
    • 2020-01-08
    • 2017-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多