Ng Serve 返回“对象原型可能只是一个对象或为空:未定义 TypeError:对象原型可能只是一个对象或为空:未定义”
2019-09-05
4287
我正在运行一个 MEAN Stack 网站,特别是我将 Angular 用于前端。我最近更新了我的 package.json 文件,将 @angular/compiler-cli 从“^7.1.4”更新为“^8.2.4”。这是我的 package.json 文件的其余部分:
{
"name": "monster-playbook",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --output-path dist"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.1.0",
"@angular/cli": "^7.1.4",
"@angular/common": "~7.1.0",
"@angular/compiler": "~7.1.0",
"@angular/compiler-cli": "^8.2.4",
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0",
"@angular/http": "^7.1.1",
"@angular/platform-browser": "~7.1.0",
"@angular/platform-browser-dynamic": "~7.1.0",
"@angular/router": "~7.1.0",
"@ng-bootstrap/ng-bootstrap": "^4.0.3",
"body-parser": "^1.18.3",
"bootstrap": "^4.0.0-beta",
"core-js": "^2.5.4",
"express": "^4.16.4",
"font-awesome": "^4.7.0",
"mongodb": "^3.1.13",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.12.4",
"@angular/language-service": "~7.1.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.3.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "^3.5.3"
}
}
从那时起,每当我尝试运行 ng serve 时,我都会遇到错误。具体来说,我目前遇到的错误是:
Object prototype may only be an Object or null: undefined
TypeError: Object prototype may only be an Object or null: undefined
at setPrototypeOf (<anonymous>)
at Object.__extends (C:\Users\Ben\Documents\Coding\Monster-Playbook\node_modules\tslib\tslib.js:64:9)
at C:\Users\Ben\Documents\Coding\Monster-Playbook\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:115:17
at C:\Users\Ben\Documents\Coding\Monster-Playbook\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:314:6
at C:\Users\Ben\Documents\Coding\Monster-Playbook\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:3:17
at Object.<anonymous> (C:\Users\Ben\Documents\Coding\Monster-Playbook\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:9:3)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789: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:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at C:\Users\Ben\Documents\Coding\Monster-Playbook\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\transform.js:20:22
at C:\Users\Ben\Documents\Coding\Monster-Playbook\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\transform.js:10:17
at Object.<anonymous> (C:\Users\Ben\Documents\Coding\Monster-Playbook\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\transform.js:16:3)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789: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:692:17)
我已经尝试过恢复更改并重新运行 npm install,但这没有帮助。我也
2个回答
我升级到了 Angular 8,并且需要将 typescript 更新到 3.4 才能解决此错误。
Chip
2020-06-10
在我的情况下,我将 angular 应用从 6.1 更新到 8.2 - npm install @angular/ [email protected] 解决了这个问题。
j_akshay
2021-08-25