使用systemjs-builder编译TypeScript时出错“获取时未处理的拒绝错误... TypeError:无法读取属性”

时间:2016-08-03 12:56:06

标签: typescript angular systemjs typescript-typings

不确定我为什么会这样做。我正在尝试使用systemjs-builder编译我的TS并收到此错误。

  

未处理的拒绝错误在app / main.js上获取文件:// ...   TypeError:无法读取属性'file:///..../src/app/main.js'   未定义

我的main.js文件

/// <reference path="../typings.d.ts" />

import { bootstrap } from '@angular/platform-browser-dynamic';
import { Location, LocationStrategy, HashLocationStrategy} from "@angular/common";
import { enableProdMode } from '@angular/core';

import { ToastsManager } from 'ng2-toastr/ng2-toastr';
import {ToastOptions} from "ng2-toastr/ng2-toastr";

import { AppComponent } from './app.component';
import { APP_ROUTER_PROVIDERS } from './app.routes';

//enableProdMode(); //Uncomment for production

let options = {
    autoDismiss: true,
    positionClass: "toast-top-right"
};

bootstrap(AppComponent, [
        APP_ROUTER_PROVIDERS,
        {
            provide: LocationStrategy, useClass: HashLocationStrategy
        },
        {
            provide: ToastOptions, useValue: new ToastOptions(options)
        },
        ToastsManager
    ])
    .catch(error => console.error(error));  

我的gulp compile-ts.js任务

module.exports = function (gulp, plugins) {
return function () {
    console.log("");
    console.log("TS: Compiling TypeScript into Javascript into Dist folder...");

    var SystemBuilder = require('systemjs-builder');
    var argv = require('yargs').argv;

    var sourceDirName = 'src';
    var sourcePath = './' + sourceDirName;
    var builder = new SystemBuilder(sourcePath, sourcePath +  "/systemjs.config.js")
    var outputFile = argv.prod ? './dist/bundle.min.js' : './dist/bundle.js';

    // The systemJS config is in `./src` and uses `node_modules` as if it's relative to it
    //      which works in lite-server because it shows `./` and `./src` as the same folder
    //      (see bs-config.json)
    //
    // In bundle though, the builder thinks that `node_modules` is relative to `./src`,
    //      not to `./`, which we need to correct by removing `src/` from path.
    builder.bundle('node_modules/*', {
        fetch: function (load, fetch) {
            load.address =
                load.address.replace(sourceDirName + "/node_modules", "node_modules");

            return fetch(load);
        }
    });

    builder.buildStatic('app', outputFile, {
        minify: argv.prod,
        mangle: argv.prod,
        rollup: argv.prod,
        // Keeps URLs in components' `templateUrl` relative to component path
        // See more at http://stackoverflow.com/a/37537725/146656
        encodeNames: false
    });

    console.log("TS: Finished");

};

};

0 个答案:

没有答案