开发者问题收集

Angular 更新新版本错误:TypeError:对象原型只能是对象或为空:未定义

2017-10-21
7185

我正在使用来自 .NET SPA 服务 的 angular 模板。因此,在将 angular 版本 4.1.2 更新到 4.4.6 后,我猜服务器端预渲染正在中断。它给出错误:

Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: Prerendering failed because of error: TypeError: Object prototype may only be an Object or null: undefined at setPrototypeOf (native) at extends (C:\Users\doom\desktop\feasion\fso.web\fso.angularclient\ClientApp\dist\main-server.js:74339:5) at C:\Users\doom\desktop\feasion\fso.web\fso.angularclient\ClientApp\dist\main-server.js:74357:5 at C:\Users\doom\desktop\feasion\fso.web\fso.angularclient\ClientApp\dist\main-server.js:74386:2 at Object.setPrototypeOf.__proto (C:\Users\doom\desktop\feasion\fso.web\fso.angularclient\ClientApp\dist\main-server.js:74313:10) at Object.c (C:\Users\doom\desktop\feasion\fso.web\fso.angularclient\ClientApp\dist\main-server.js:74316:2) at webpack_require (C:\Users\doom\desktop\feasion\fso.web\fso.angularclient\ClientApp\dist\main-server.js:20:30) at Object.setPrototypeOf. proto (C:\Users\doom\desktop\feasion\fso.web\fso.angularclient\ClientApp\dist\main-server.js:34187:203) at Object. (C:\Users\doom\desktop\feasion\fso.web\fso.angularclient\ClientApp\dist\main-server.js:34190:2) at webpack_require (C:\Users\doom\desktop\feasion\fso.web\fso.angularclient\ClientApp\dist\main-server.js:20:30) Current directory is: C:\Users\doom\desktop\feasion\fso.web\fso.angularclient

at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.d__7`1.MoveNext() --- End of stack trace from previous location where exception was thrown ---

这是 package.json

{


"name": "feasionangular",
  "version": "0.1.2",
  "scripts": {    
    "test": "karma start ClientApp/test/karma.conf.js"
  },
  "dependencies": {
    "@angular/animations": "4.4.6",
    "@angular/cdk": "^2.0.0-beta.10",
    "@angular/common": "4.4.6",
    "@angular/compiler": "4.4.6",
    "@angular/core": "4.4.6",
    "@angular/forms": "4.4.6",
    "@angular/http": "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",
    "@angular/material": "^2.0.0-beta.10",
    "@angular/flex-layout": "^2.0.0-beta.9",
    "@types/node": "7.0.18",
    "angular2-jwt": "0.2.3",
    "angular2-moment": "1.7.0",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^2.0.5",
    "aspnet-webpack": "^1.0.29",
    "awesome-typescript-loader": "3.1.3",
    "bootstrap": "3.3.7",
    "css": "2.2.1",
    "css-loader": "0.28.1",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "2.1.0",
    "file-loader": "0.11.1",
    "hammerjs": "2.0.8",
    "html-loader": "0.4.5",
    "isomorphic-fetch": "2.2.1",
    "json-loader": "0.5.4",
    "jsrsasign": "8.0.3",
    "ngx-bootstrap": "1.9.3",
    "ngx-carousel": "1.2.0",
    "ngx-infinite-scroll": "0.5.1",
    "normalize.css": "^7.0.0",
    "preboot": "4.5.2",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.4.2",
    "style-loader": "0.17.0",
    "to-string-loader": "1.1.5",
    "typescript": "2.3.2",
    "tslint": "5.8.0",
    "url-loader": "0.5.8",
    "webpack": "2.5.1",
    "webpack-hot-middleware": "2.18.0",
    "webpack-merge": "4.1.0",
    "zone.js": "0.8.10"
  },
  "devDependencies": {
    "@types/chai": "3.5.2",
    "@types/jasmine": "2.5.47",
    "chai": "3.5.0",
    "jasmine-core": "2.6.1",
    "karma": "1.7.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.1.1",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.1.0",
    "karma-webpack": "2.0.3"
  }
}

当我降级 angular 版本时,不会抛出错误,但我需要使用较新的版本。

2个回答

您是否尝试过升级其他软件包,例如 “preboot”:“5.1.7”, “rxjs”:“5.5.2”, “typescript”:“2.6.1”,

Mei
2017-11-05

您可以更新 @angular/compiler

rikkep
2019-10-07