Angular 8 to 9 upgrade error when trying to build

牧云@^-^@ 提交于 2021-02-08 21:31:11

问题


I'm trying to upgrade from Angular 8 to 9 and I'm getting this error when I do ng build. It looks like the problem is in the babel package in vendor.js.

[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)

Anyone know how to fix this error? Thanks. Here's 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:


Go to your src/main.ts file and remove the following line

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

now run ng build

The issue will be fixed.



来源:https://stackoverflow.com/questions/60386358/angular-8-to-9-upgrade-error-when-trying-to-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!