首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular TypeError:对象原型只能是对象或null:未定义

Angular TypeError:对象原型只能是对象或null:未定义
EN

Stack Overflow用户
提问于 2020-10-28 18:09:37
回答 1查看 455关注 0票数 0

在我尝试安装ExcelJs (npm install --save exceljs)之前,我有一个正在运行的项目。

在那之后,我开始收到各种错误,比如Cannot read property ‘Minus’ of undefinedCannot find module 'postcss-value-something',这些错误都是通过npm iing解决的,无论缺少的是什么。

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

在遇到这些问题后,我删除了excelJ,希望能恢复一些正常状态,然而,没有这样的运气。

完整错误如下:

代码语言:javascript
复制
    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的内容如下:

代码语言:javascript
复制
 "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返回以下内容:

代码语言:javascript
复制
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版本甚至typescript有关,就像我在其他地方看到的那样,但是似乎没有任何关于哪个版本应该与什么一起使用的指南。

任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2020-10-28 18:24:33

你的angular包版本太不同步了!不知何故,您的编译器-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更新不起作用,您最好使用以下步骤:

将源代码保存在ng new xxx

  • copy下,并保存您认为值得保存的任何其他文件,如package.json以检查您正在使用的任何非angular包。

  • 通过使用ng new xxx

  • copy
  • src folder
  • upgrade新项目来删除全局项目的整个项目,但跳过main.tspolyfills.ts和D20文件。由于最新的angular cli version
  • optional:有重大更改,因此请使用您可能已做的任何自定义更改来更新这些未复制的文件,如package.json

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

顺便说一句,如果您使用npm update^将只更新已安装软件包的次要版本。阅读更多here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64570632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档