Search code examples
javascriptangularsystemjs

SystemJS in Angular2 defaultExtension doesn't work


Something wrong with my new Angular2 application. I call my main boot file next way within my index.html:

SystemJS.config({
    packages: {
        app: {
            format: 'register',
            defaultExtension: 'js'
        }
    }
});

SystemJS.import('src/app/prod/boot').then(null, console.error.bind(console));

In my console i see some errors:

enter image description here

If i specify an extension explicity:

SystemJS.import('src/app/prod/boot.js').then(null, console.error.bind(console));

All will be OK, but i have the same problem inside my component with import another component without specify an extension:

import {Component} from 'angular2/core';
import {ROUTER_DIRECTIVES, RouteConfig, RouteParams} from 'angular2/router';
import {AppComponent} from './app.component';

enter image description here


Solution

  • It's because your package isn't app but src/app. Either move your index.html inside your src folder or change the packages definition of your SystemJS config to this:

    SystemJS.config({
        packages: {
            'src/app': {
                format: 'register',
                defaultExtension: 'js'
            }
        }
    });