TypeError:对象原型只能是一个对象或为空:未定义 Angular
我尝试通过“ng serve”启动我的 Web 应用程序,出现此错误。无法弄清楚原因。
我不确定错误到底在告诉我什么。我尝试更新所有依赖项。我查看了几乎所有类似的问题解决方案,但都没有奏效。我不知道这是编译器错误、typescript 还是依赖项错误。
[error] TypeError: Object prototype may only be an Object or null: undefined at setPrototypeOf () at Object.__extends (C:\Users\9090\Documents\project\FR\node_modules@angular\compiler-cli\node_modules\tslib\tslib.js:68:9) at C:\Users\9090\Documents\project\FR\node_modules@angular\compiler-cli\src\ngtsc\indexer\src\template.js:118:17 at C:\Users\9090\Documents\project\FR\node_modules@angular\compiler-cli\src\ngtsc\indexer\src\template.js:325:6 at C:\Users\9090\Documents\project\FR\node_modules@angular\compiler-cli\src\ngtsc\indexer\src\template.js:3:17 at Object. (C:\Users\9090\Documents\project\FR\node_modules@angular\compiler-cli\src\ngtsc\indexer\src\template.js:9:3) at Module._compile (internal/modules/cjs/loader.js:1138:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) at Module.load (internal/modules/cjs/loader.js:986:32) at Function.Module._load (internal/modules/cjs/loader.js:879:14) at Module.require (internal/modules/cjs/loader.js:1026:19) at require (internal/modules/cjs/helpers.js:72:18) at C:\Users\9090\Documents\project\FR\node_modules@angular\compiler-cli\src\ngtsc\indexer\src\transform.js:21:22 at C:\Users\9090\Documents\project\FR\node_modules@angular\compiler-cli\src\ngtsc\indexer\src\transform.js:10:17 at Object. (C:\Users\9090\Documents\project\FR\node_modules@angular\compiler-cli\src\ngtsc\indexer\src\transform.js:16:3) at Module._compile (internal/modules/cjs/loader.js:1138:30)
我的 package.json:
{
"name": "Client",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@agm/core": "^1.1.0",
"@angular-devkit/core": "^10.0.1",
"@angular-devkit/schematics": "^10.0.1",
"@angular/animations": "^8.2.14",
"@angular/cdk": "^7.3.7",
"@angular/common": "^8.0.3",
"@angular/compiler": "^8.0.3",
"@angular/core": "^10.0.3",
"@angular/forms": "^8.0.3",
"@angular/material": "^7.3.7",
"@angular/platform-browser": "^8.0.3",
"@angular/platform-browser-dynamic": "^8.0.3",
"@angular/router": "^8.0.3",
"@fullcalendar/core": "^4.2.0",
"@fullcalendar/daygrid": "^4.2.0",
"@fullcalendar/interaction": "^4.2.0",
"@fullcalendar/timegrid": "^4.2.0",
"acorn": "^6.4.1",
"agm-direction": "^0.7.9",
"angular-fusioncharts": "^3.0.4",
"bootstrap": "^4.4.1",
"chart.js": "^2.8.0",
"core-js": "^2.4.1",
"events": "^3.0.0",
"font-awesome": "^4.7.0",
"fullcalendar": "^3.10.0",
"hammerjs": "^2.0.8",
"install": "^0.12.2",
"jquery": "^3.5.1",
"popper.js": "^1.12.9",
"primeicons": "^1.0.0",
"primeng": "^8.1.1",
"quill": "^1.3.7",
"rxjs": "^6.5.2",
"rxjs-compat": "^6.0.0-rc.0",
"save": "^2.4.0",
"sweetalert": "^2.1.2",
"sweetalert2": "^9.5.3",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.1000.1",
"@angular/cli": "^10.0.1",
"@angular/compiler-cli": "^10.0.3",
"@angular/language-service": "^8.0.3",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.118",
"codelyzer": "^5.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^5.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^7.0.0",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~3.4.5"
}
}
我不认为不同的 angular 包主版本能够正常工作。尝试将所有 angular 包更新为相同的主版本。在 WebStorm 中,您可以使用语法高亮来收集最新版本。
然后尝试在项目文件夹中执行以下操作:
ng update
这将向您显示要更新的具体内容。
首先,使用以下命令在项目文件夹中检查任何过时的节点模块,
npm outdated
过时的命令将列出所有未更新的软件包
是否有任何过时的软件包,然后使用以下命令升级它们,
npm update --save/--save-dev
请更新其余依赖项。例如,typescript 已经过时了。尝试升级“rxjs”:“6.6.0”、“typescript”:“^3.9.6”等软件包。