Javascript 角度,Karma(SystemJS)XHR错误(404未找到)-[单独的Src/构建]

Javascript 角度,Karma(SystemJS)XHR错误(404未找到)-[单独的Src/构建],javascript,angular,typescript,karma-runner,systemjs,Javascript,Angular,Typescript,Karma Runner,Systemjs,我正在使用Angular(2)、typescript、karma和SystemJs构建系统 应用程序构建可以完美地工作,将src文件从apps/samples/**带到build/**这是构建目录的结构。我运行我的吞咽任务生成文件和浏览器同步向我显示我的应用:) 现在,正如前面提到的,我对typescript或构建的任何其他部分都没有问题。当运行karma时,问题出现了。我不断收到如下错误: Chrome 55.0.2883 (Windows 10 0.0.0) ERROR: 'Unhandle

我正在使用Angular(2)、typescript、karma和SystemJs构建系统

应用程序构建可以完美地工作,将src文件从apps/samples/**带到build/**这是构建目录的结构。我运行我的吞咽任务生成文件和浏览器同步向我显示我的应用:)

现在,正如前面提到的,我对typescript或构建的任何其他部分都没有问题。当运行karma时,问题出现了。我不断收到如下错误:

Chrome 55.0.2883 (Windows 10 0.0.0) ERROR: 'Unhandled Promise rejection:', '(SystemJS) XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error: XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error loading http://localhost:9876/base/systemjs.config.js', '; Zone:', '<root>', '; Task:', 'Promise.then', '; Value:', Error{stack: '(SystemJS) XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error: XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error loading http://localhost:9876/base/systemjs.config.js', message: '(SystemJS) XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error: XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error loading http://localhost:9876/base/systemjs.config.js', originalStack: 'Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error: XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error loading http://localhost:9876/base/systemjs.config.js', zoneAwareStack: 'Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error: XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error loading http://localhost:9876/base/systemjs.config.js', name: 'Error', toString: function toString() { ... }, originalErr: Error{stack: 'Error: XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js', message: 'XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js', originalStack: 'Error: XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js', zoneAwareStack: 'Error: XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js', name: 'Error', toString: function toString() { ... }}}, '(SystemJS) XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error: XHR error (404 Not Found) loading http://localhost:9876/base/systemjs.config.js
    Error loading http://localhost:9876/base/systemjs.config.js'
这是我的karma-test-shim.js

// /*global jasmine, __karma__, window*/
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.

// Uncomment to get full stacktrace output. Sometimes helpful, usually not.
// Error.stackTraceLimit = Infinity; //

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;

// builtPaths: root paths for output ("built") files
// get from karma.config.js, then prefix with '/base/' (default is 'app/')
var builtPaths = (__karma__.config.builtPaths || ['app/'])
.map(function (p) {
    return '/base/build/' + p;
});

__karma__.loaded = function () {
};

function isJsFile(path) {
    return path.slice(-3) == '.js';
}

function isSpecFile(path) {
    return /\.spec\.(.*\.)?js$/.test(path);
}

// Is a "built" file if is JavaScript file in one of the "built" folders
function isBuiltFile(path) {
    return isJsFile(path) &&
        builtPaths.reduce(function (keep, bp) {
            return keep || (path.substr(0, bp.length) === bp);
    }, false);
}

var allSpecFiles = Object.keys(window.__karma__.files)
    .filter(isSpecFile)
    .filter(isBuiltFile);

System.config({
    baseURL: 'base/',
    // Extend usual application package list with test folder
    packages: {'testing': {main: 'index.js', defaultExtension: 'js'}},

    // Assume npm: is set in `paths` in systemjs.config
    // Map the angular testing umd bundles
    map: {
        '@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
        '@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
        '@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
        '@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
        '@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
        '@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
        '@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
        '@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js',
    },
});

System.import('systemjs.config.js').then(function (m) {
    console.log(m);
})
//.then(importSystemJsExtras)
.then(initTestBed)
.then(initTesting);

/** Optional SystemJS configuration extras. Keep going w/o it */
 function importSystemJsExtras() {
     return System.import('systemjs.config.extras.js')
         .catch(function (reason) {
             console.log(
              'Warning: System.import could not load the optional "systemjs.config.extras.js". Did you omit it by accident? Continuing without it.'
        );
        console.log(reason);
    });
}

 function initTestBed() {
    return Promise.all([
        System.import('@angular/core/testing'),
        System.import('@angular/platform-browser-dynamic/testing')
    ])

    .then(function (providers) {
        var coreTesting = providers[0];
        var browserTesting = providers[1];

        coreTesting.TestBed.initTestEnvironment(
            browserTesting.BrowserDynamicTestingModule,
            browserTesting.platformBrowserDynamicTesting());
    })
}

// Import all spec files and start karma
function initTesting() {
    return Promise.all(
        allSpecFiles.map(function (moduleName) {
        return System.import(moduleName);
    })
)
    .then(__karma__.start, __karma__.error);
}
现在我得到了错误,读了一篇又一篇的帖子,有人提到了karma放文件的基本目录,有人提到了包和模块等等,但现在给出了karma为什么不加载系统js的明确答案

我是angular2的neewb,更喜欢构建结构,因此不会改变这一方面,即使我错过了一些非常简单的东西,其他任何东西都会有帮助。

尝试改变:

{ pattern: 'build/systemjs.config.js', included: false, watched: false },
{ pattern: 'build/systemjs.config.extras.js', included: false, watched: false }
致:


你把它弄好了吗?我也有同样的问题。
// /*global jasmine, __karma__, window*/
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.

// Uncomment to get full stacktrace output. Sometimes helpful, usually not.
// Error.stackTraceLimit = Infinity; //

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;

// builtPaths: root paths for output ("built") files
// get from karma.config.js, then prefix with '/base/' (default is 'app/')
var builtPaths = (__karma__.config.builtPaths || ['app/'])
.map(function (p) {
    return '/base/build/' + p;
});

__karma__.loaded = function () {
};

function isJsFile(path) {
    return path.slice(-3) == '.js';
}

function isSpecFile(path) {
    return /\.spec\.(.*\.)?js$/.test(path);
}

// Is a "built" file if is JavaScript file in one of the "built" folders
function isBuiltFile(path) {
    return isJsFile(path) &&
        builtPaths.reduce(function (keep, bp) {
            return keep || (path.substr(0, bp.length) === bp);
    }, false);
}

var allSpecFiles = Object.keys(window.__karma__.files)
    .filter(isSpecFile)
    .filter(isBuiltFile);

System.config({
    baseURL: 'base/',
    // Extend usual application package list with test folder
    packages: {'testing': {main: 'index.js', defaultExtension: 'js'}},

    // Assume npm: is set in `paths` in systemjs.config
    // Map the angular testing umd bundles
    map: {
        '@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
        '@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
        '@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
        '@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
        '@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
        '@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
        '@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
        '@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js',
    },
});

System.import('systemjs.config.js').then(function (m) {
    console.log(m);
})
//.then(importSystemJsExtras)
.then(initTestBed)
.then(initTesting);

/** Optional SystemJS configuration extras. Keep going w/o it */
 function importSystemJsExtras() {
     return System.import('systemjs.config.extras.js')
         .catch(function (reason) {
             console.log(
              'Warning: System.import could not load the optional "systemjs.config.extras.js". Did you omit it by accident? Continuing without it.'
        );
        console.log(reason);
    });
}

 function initTestBed() {
    return Promise.all([
        System.import('@angular/core/testing'),
        System.import('@angular/platform-browser-dynamic/testing')
    ])

    .then(function (providers) {
        var coreTesting = providers[0];
        var browserTesting = providers[1];

        coreTesting.TestBed.initTestEnvironment(
            browserTesting.BrowserDynamicTestingModule,
            browserTesting.platformBrowserDynamicTesting());
    })
}

// Import all spec files and start karma
function initTesting() {
    return Promise.all(
        allSpecFiles.map(function (moduleName) {
        return System.import(moduleName);
    })
)
    .then(__karma__.start, __karma__.error);
}
{ pattern: 'build/systemjs.config.js', included: false, watched: false },
{ pattern: 'build/systemjs.config.extras.js', included: false, watched: false }
{ pattern: '/systemjs.config.js', included: false, watched: false },
{ pattern: '/systemjs.config.extras.js', included: false, watched: false }