Karma cannot load Angular 2 Component

不想你离开。 提交于 2019-12-08 18:19:29

I recently came across this same issue and I came to the conclusion that SystemJS is responsible for default extensions (should be 'js'). Make sure that your ng2 app folder is properly connected with your systemjs.config file.

(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // app is within the app folder
      app: 'app', <<<<<<<------ HERE

      '@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/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',

      // other libraries
      'rxjs':                       'npm:rxjs',
      'angular-in-memory-web-api':  'npm:angular-in-memory-web-api'
    },
    packages: {
      app: { <<<<<<<------ HERE
        main: './main.js',
        defaultExtension: 'js' <<<<<<----- Important!!
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular-in-memory-web-api': {
        main: 'server/server.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);

If this is correct and it is still having issues than it's probably an inconsistency in how your karma web-server and your node server serve your client files. You can add a proxy in your karma.conf file...

proxies: {
  // required for component assets fetched by Angular's compiler
  "/app/": "/base/client/app/"
},

Hope this helps! c:

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