本文介绍了将 Angular 4 升级到 Angular 8 后的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我在我的应用程序中使用 Angular 4 和 system.js.现在我将其更新为 Angular 8.

Currently I am using Angular 4 in my application with system.js. Now I am updating it to Angular 8.

为此,我遵循以下 2 个链接:

For that I follow below 2 links:

将 angular 4 项目升级到 angular 6

https://www.talkdotnet.com/upgrade-angular-4-app-angular-5-visual-studio-2017/

我做了以下更改:

  1. 更新了 package.json 中的所有包
  2. http 到 httpclient
  3. httpmodule 到 httpclientmodule
  4. http 请求 (map.json)
  5. rxjs 变化

当我在所有更改后运行应用程序时出现以下错误:

When I run application after all changes and I am getting below error:

未捕获的语法错误:意外标记<"systemjs.config.js:6 Uncaught TypeError: System.config is not a function在 systemjs.config.js:6在 systemjs.config.js:101

Uncaught SyntaxError: Unexpected token '<'systemjs.config.js:6 Uncaught TypeError: System.config is not a function at systemjs.config.js:6 at systemjs.config.js:101

我需要从 system.js 到任何映射吗请在下面的 system.js 中找到:

Do I need to any mapping from system.jsPlease find below system.js:

    paths: {

        'npm:': './node_modules/'
    },

    map: {

        'app': './app',

        // angular bundles
        '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
        '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
        '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
        '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
        '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
        '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
        '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
        '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
        '@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
        '@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
        '@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',

        // other libraries
        'rxjs': 'npm:rxjs',
        'lodash': 'npm:lodash',
        'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
        '@ng-bootstrap/ng-bootstrap': 'npm:@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js',
        '@bento.ui/bento-ng': 'npm:@bento.ui/bento-ng/bundles/bento.ui.js',
        'ngx-restangular': 'npm:ngx-restangular/dist/esm/src',
        'angular-2-local-storage': 'npm:angular-2-local-storage/dist',
        '@ngx-translate/core': 'npm:@ngx-translate/core/bundles/core.umd.js',
        '@ngx-translate/http-loader': 'npm:@ngx-translate/http-loader/bundles/http-loader.umd.js',
        'angular2-tinymce': 'npm:angular2-tinymce/dist',
        'tinymce': './Scripts/vendors/tinymce',
        'ng2-dnd': 'npm:ng2-dnd/bundles/index.umd.js',
    },
    meta: {
        './Scripts/vendors/tinymce/plugins/advlist/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/plugins/autoresize/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/plugins/code/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/plugins/link/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/plugins/lists/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/plugins/paste/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/plugins/table/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/plugins/image/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/plugins/textcolor/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/plugins/imagetools/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/plugins/contextmenu/plugin.js': { format: 'global' },
        './Scripts/vendors/tinymce/themes/modern/theme.js': { format: 'global' },
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
        app: {
            main: './main.js',
            defaultExtension: 'js'
            //meta: {
            //    './*.js': {
            //        loader: 'systemjs-angular-loader.js'
            //    }
            //}
        },
        'ngx-restangular': {
            main: './index',
            defaultExtension: 'js'
        },
        rxjs: {
            main: "./Rx.js",
            defaultExtension: 'js'
        },
        lodash: {
            main: './index.js',
            defaultExtension: 'js'
        },
        'angular-2-local-storage': {
            main: './index',
            defaultExtension: 'js'
        },
        moment: {
            main: './moment.js',
            defaultExtension: 'js'
        },
        '@ngx-translate/core': {
            defaultExtension: 'js'
        },
        'angular2-tinymce': {
            main: 'index.js',
            defaultExtension: 'js'
        },
        'tinymce': {
            defaultExtension: 'js'
        }
    },
    warnings: true
});

以下是package.json:

and below is package.json:

  "dependencies": {
    "@angular/animations": "8.2.14",
    "@angular/common": "8.2.14",
    "@angular/compiler": "8.2.14",
    "@angular/compiler-cli": "8.2.14",
    "@angular/core": "8.2.14",
    "@angular/forms": "8.2.14",
    "@angular/http": "7.2.15",
    "@angular/platform-browser": "^8.2.14",
    "@angular/platform-browser-dynamic": "8.2.14",
    "@angular/platform-server": "8.2.14",
    "@angular/router": "8.2.14",
    "@angular/upgrade": "8.2.14",
    "@ng-bootstrap/ng-bootstrap": "5.1.4",
    "@ngx-translate/core": "11.0.1",
    "@ngx-translate/http-loader": "4.0.0",
    "@types/lodash": "4.14.149",
    "angular-2-local-storage": "3.0.2",
    "angular-in-memory-web-api": "0.9.0",
    "angular2-tinymce": "3.3.0",
    "bootstrap": "4.3.1",
    "core-js": "3.4.2",
    "font-awesome": "4.7.0",
    "ie-shim": "0.1.0",
    "lodash": "4.17.15",
    "markdown-it": "10.0.0",
    "ng2-dnd": "5.0.2",
    "ngx-restangular": "5.0.0",
    "rxjs": "^6.5.3",
    "systemjs": "6.1.5",
    "tinymce": "5.1.2",
    "topojson": "3.0.2",
    "typescript": "2.5.3",
    "zone.js": "0.10.2"
  },
  "devDependencies": {
    "@types/node": "12.12.14",
    "fs": "0.0.2",
    "gulp": "4.0.2",
    "gulp-cache-bust": "1.4.1",
    "gulp-clean-css": "4.2.0",
    "gulp-concat": "2.6.1",
    "gulp-filter": "6.0.0",
    "gulp-foreach": "0.1.0",
    "gulp-inline-ng2-styles": "0.0.1",
    "gulp-inline-ng2-template": "5.0.1",
    "gulp-rev": "9.0.0",
    "gulp-sourcemaps": "2.6.5",
    "gulp-typescript": "5.0.1",
    "gulp-uglify": "3.0.2",
    "rimraf": "3.0.0",
    "run-sequence": "2.2.1",
    "systemjs-builder": "0.16.15",
    "typescript": "3.7.2",
    "vinyl-buffer": "1.0.1",
    "vinyl-source-stream": "2.0.0"
  },
  "repository": {}
}

提前致谢.

推荐答案

这里是 Angular 更新指南来自角度网站.

Here is the Angular Update Guide from the angular website.

我注意到您在开发依赖项中使用了两个版本的 typescript,2.5.3"和3.7.2",我只会使用一个版本(angular 推荐的版本)~3.1".

I noticed you are using two versions of typescript, "2.5.3" and "3.7.2" in your dev dependencies, I would use only one version (the recommended version by angular) ~"3.1".

我建议您一次更新 1 个版本,我知道它的过程如此漫长,但您解决问题比从 4 跳到 8 更容易.

I Recommend you update 1 version at a time, I know its so lengthy process but you it will be easier to fix issues than just jumping from 4 to 8.

这篇关于将 Angular 4 升级到 Angular 8 后的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 22:37