尝试构建时出现Angular 8到9升级错误

时间:2020-02-25 01:38:48

标签: angular angular-cli

我正在尝试从Angular 8升级到9,并且在进行ng build时遇到此错误。看来问题出在vendor.js的babel软件包中。

enter image description here

[error] SyntaxError: C:\Dev\allverse3\ClientApp\vendor-es2015.js: 'with' in strict mode (139204:4)

[0m [90m 139202 | [39m  [33mWindow_run[39m[33m:[39m [36mfunction[39m _run(code[33m,[39m file) {[0m
[0m [90m 139203 | [39m    [36mif[39m (file) code [33m+=[39m [32m'\n//@ sourceURL='[39m [33m+[39m file[33m;[39m[0m
[0m[31m[1m>[22m[39m[90m 139204 | [39m    [36mwith[39m([36mthis[39m) eval(code)[33m;[39m[0m
[0m [90m        | [39m    [31m[1m^[22m[39m[0m
[0m [90m 139205 | [39m  }[33m,[39m[0m
[0m [90m 139206 | [39m  [33mEventHandlerBuilder_build[39m[33m:[39m [36mfunction[39m build() {[0m
[0m [90m 139207 | [39m    [36mtry[39m {[0m
    at Parser.raise (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:7017:17)
    at Parser.parseWithStatement (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:11174:12)
    at Parser.parseStatementContent (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:10763:21)
    at Parser.parseStatement (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:10690:17)
    at Parser.parseBlockOrModuleBlockBody (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:11264:25)
    at Parser.parseBlockBody (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:11251:10)
    at Parser.parseBlock (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:11235:10)
    at Parser.parseFunctionBody (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:10252:24)
    at Parser.parseFunctionBodyAndFinish (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:10222:10)
    at C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:11394:12
    at Parser.withTopicForbiddingContext (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:10565:14)
    at Parser.parseFunction (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:11393:10)
    at Parser.parseFunctionExpression (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:9714:17)
    at Parser.parseExprAtom (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:9622:21)
    at Parser.parseExprSubscripts (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:9259:23)
    at Parser.parseMaybeUnary (C:\Dev\allverse3\ClientApp\node_modules\@angular-devkit\build-angular\node_modules\@babel\parser\lib\index.js:9239:21)

有人知道如何解决此错误吗?谢谢。这是package.json。

{
  "name": "allverse3",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:ssr": "ng run allverse3:server:dev",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "9.0.2",
    "@angular/common": "9.0.2",
    "@angular/compiler": "9.0.2",
    "@angular/core": "9.0.2",
    "@angular/forms": "9.0.2",
    "@angular/http": "^7.2.16",
    "@angular/platform-browser": "9.0.2",
    "@angular/platform-browser-dynamic": "9.0.2",
    "@angular/platform-server": "9.0.2",
    "@angular/router": "9.0.2",
    "@babel/core": "^7.8.4",
    "@babel/preset-env": "^7.8.4",
    "@babel/preset-typescript": "^7.8.3",
    "@nguniversal/module-map-ngfactory-loader": "8.2.6",
    "aspnet-prerendering": "^3.0.1",
    "bootstrap": "^4.4.1",
    "component": "^1.1.0",
    "core-js": "^3.6.4",
    "jquery": "3.4.1",
    "oidc-client": "^1.10.1",
    "popper.js": "^1.16.1",
    "rxjs": "^6.5.4",
    "rxjs-compat": "^6.5.4",
    "tslib": "^1.11.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.3",
    "@angular/cli": "9.0.3",
    "@angular/compiler-cli": "9.0.2",
    "@angular/language-service": "9.0.2",
    "@types/jasmine": "^3.5.6",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^13.7.4",
    "codelyzer": "^5.2.1",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "^2.1.1",
    "karma-jasmine": "~3.1.1",
    "karma-jasmine-html-reporter": "^1.5.2",
    "typescript": "~3.7.0"
  },
  "optionalDependencies": {
    "node-sass": "^4.9.3",
    "protractor": "~5.4.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}

1 个答案:

答案 0 :(得分:5)

转到您的src/main.ts文件并删除以下行

export { renderModule, renderModuleFactory } from '@angular/platform-server';

现在运行ng build

问题将得到解决。