Angular 2应用程序使用asp.net核心在Firefox和IE中不起作用(tsconfig问题)

时间:2016-09-29 09:36:11

标签: angular

这是Visual Studio 2015的Angular 2最终版应用程序。 gulp用于从节点模块生成库

我的应用在Chrome和Edge中运行良好,但在Firefox和IE中无法正常工作

   *

Firefox错误:

    *
       Error: (SystemJS) missing = in const declaration
    @http://localhost:50135/scripts/app.module.js:13:25
    @http://localhost:50135/scripts/app.module.js:1:31
    @http://localhost:50135/scripts/app.module.js:1:2
    @http://localhost:50135/scripts/boot.js:3:22
    @http://localhost:50135/scripts/boot.js:1:31
    @http://localhost:50135/scripts/boot.js:1:2
    ZoneDelegate.prototype.invoke@http://localhost:50135/libs/zone.js/dist/zone.js:192:19
    Zone.prototype.run@http://localhost:50135/libs/zone.js/dist/zone.js:85:24
    scheduleResolveOrReject/<@http://localhost:50135/libs/zone.js/dist/zone.js:451:52
    ZoneDelegate.prototype.invokeTask@http://localhost:50135/libs/zone.js/dist/zone.js:225:23
    Zone.prototype.runTask@http://localhost:50135/libs/zone.js/dist/zone.js:125:28
    drainMicroTaskQueue@http://localhost:50135/libs/zone.js/dist/zone.js:357:25
    ZoneTask/this.invoke@http://localhost:50135/libs/zone.js/dist/zone.js:297:25

    Evaluating http://localhost:[enter image description here][1]50135/scripts/app.component.js
    Evaluating http://localhost:50135/scripts/app.module.js
    Evaluating http://localhost:50135/scripts/boot.js
    Error loading http://localhost:50135/scripts/boot.js

这是我的tsconfig

    {

    "compileOnSave": true,
    "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
   "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noEmitOnError": true,
    "noImplicitAny": false,
    "outDir": "../wwwroot/scripts/",
    "removeComments": false

    },
    "exclude": [
    "node_modules",
    "typings/index",
    "typings/index.d.ts"
    ]
    }


     **this is my package.json**

    {
    "version": "1.0.0",
    "name": "ngcorecontacts",
    "scripts": {
    "postinstall": "typings install",
    "typings": "typings"
    },
    "dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "@angular/upgrade": "2.0.0",
    "@angular/platform-server": "2.0.0",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "^5.0.0-beta.12",
    "es6-shim": "0.35.1",
    "systemjs": "0.19.38",
    "zone.js": "^0.6.23",
    "jquery": "3.1.0",

"angular2-in-memory-web-api": "0.0.20",
"bootstrap": "^3.3.6"

    },
    "devDependencies": {
    typescript": "^2.0.2",
    "gulp": "3.9.1",
    "path": "0.12.7",
    "gulp-clean": "0.3.2",
    "gulp-concat": "^2.6.0",
    "gulp-typescript": "^2.13.6",
    "typings": "^1.3.1",
    "gulp-tsc": "^1.2.0"
    }
    }

这是我的systemjs.config

       System configuration for Angular 2 samples

        Adjust as necessary for your application needs.
        */
        (function (global) {
        // map tells the System loader where to look for things

        // packages tells the System loader how to load when no filename and/or no extension
        var packages = {
        app: { main: 'boot.js', defaultExtension: 'js' },
        'rxjs': { defaultExtension: 'js' },
        'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
        '@angular/core': { main: 'core.umd.min.js' },
        '@angular/common': { main: 'common.umd.min.js' },
        '@angular/compiler': { main: 'compiler.umd.min.js' },
        '@angular/platform-browser': { main: 'platform-browser.umd.min.js' },
        '@angular/platform-browser-dynamic': { main: 'platform-browser-dynamic.umd.min.js' },

        };
        var map = {
        'app': 'scripts', // 'dist',
       '@angular': 'libs/@angular',
        'angular2-in-memory-web-api': 'libs/angular2-in-memory-web-api',
        'rxjs': 'libs/rxjs'
        };
        var ngPackageNames = [
        'common',
        'compiler',
        'core',
        'forms',
        'http',
        'platform-browser',
        'platform-browser-dynamic',
        'router',
        'router-deprecated',
        'upgrade',
        ];
       // Individual files (~300 requests):
        function packIndex(pkgName) {
        packages['@angular/' + pkgName] = { main: 'index.js', defaultExtension: 'js' };
        }
        // Bundled (~40 requests):
        function packUmd(pkgName) {
        packages['@angular/' + pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
        }
        // Most environments should use UMD; some (Karma) need the individual index files
        var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
        // Add package entries for angular packages
        ngPackageNames.forEach(setPackageConfig);
        var config = {
        defaultJSExtensions: true,
        map: map,
        packages: packages
        };
        System.config(config);
        })(this);

我尝试了很多来解决这个问题,但仍然没有工作,请指导我解决同样的问题。 我认为它是一个tsconfig文件问题。 这个应用程序在chrome中正常运行,同样的代码在system.src文件中生成错误,以加载所有模块和bootstrap(main.ts)文件

2 个答案:

答案 0 :(得分:1)

你的目标是“目标”:“es6”。

Firefox还不支持完全ES6,你可以在这里看到:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla

不符合ES6规范的功能(最后更新时间为2016年9月19日,下午4:34:50)

以下功能(部分)在Firefox中实现,但不符合规范。这有几个可能的原因:Firefox的实现基于ES6规范的较旧草案,或者Firefox的当前实现是在将类似功能添加到ES6规范之前添加的实验设计。

  • 旧版迭代器和生成器(JS 1.7,Firefox 2)
  • 解构分配(JS 1.7,Firefox 2)(ES6合规性错误1055984)
  • const(JS 1.5,Firefox 1.0)(在Firefox 51中实现的ES6合规性错误950547)
  • let(JS 1.7,Firefox 2)(在Firefox 51中实现的ES6合规性错误950547)

您可以将目标更改为ES5以确保兼容性。

希望这有帮助

答案 1 :(得分:0)

出现此问题是因为您在for..of循环中使用了 const 关键字(here)。 这绝对是有效的声明,但它在Edge中不起作用(不用Firefox测试)。所以我认为,将所有事件更改为

会更好