Search code examples
angularsystemjs

systemJS "unexpected token error" when importing 3rd party library


I am trying to use angular2-datatable in an angular2 application but I am getting the following error when trying to run the application after putting in the imports in the AppModule

Error: (SystemJS) Unexpected token <

here is the AppModule

 import { NgModule } from '@angular/core';
 import { BrowserModule } from '@angular/platform-browser';
 import { HttpModule } from '@angular/http';
 import { AppComponent } from './app.component'
 import { FormsModule } from '@angular/forms';
 import { RouterModule } from '@angular/router';
 import { APP_BASE_HREF } from '@angular/common';
 import { SelectModule } from 'angular2-select';
 import { AppRoutes } from './app.routes';
 import { DataTableModule } from "angular2-datatable";


@NgModule({
declarations: [
AppComponent
],
providers: [{ provide: APP_BASE_HREF, useValue: '/' }],
imports: [
BrowserModule,
HttpModule,
FormsModule,
SelectModule,
DataTableModule,
RouterModule.forRoot(AppRoutes)],
bootstrap: [AppComponent]
})
export class AppModule { }

and here is my systemjs.config

(function (global) {
System.config({
    paths: {
        // paths serve as alias
        'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
        // our app is within the app folder
        app: 'app',
        // angular bundles
        '@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',
        // other libraries
        'rxjs': 'npm:rxjs',
        'angular2-select': 'node_modules/angular2-select',
        'angular2-datatable': 'node_modules/angular2-datatable'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
        app: {
            main: './main.js',
            defaultExtension: 'js'
        },
        rxjs: {
            defaultExtension: 'js'
        },
        'angular2-select': {
            main: 'index.js',
            defaultExtension: 'js'
        },
        'angular2-datatable': {
            main: 'index.js',
            defaultExtension: 'js'
        }
    }
});
})(this);

I have imported other libraries this same way so I am not sure what I am missing. Any thoughts?


Solution

  • Looks like you need to makes sure lodash is also referenced in you system js. try adding this...

    'angular2-select': 'node_modules/angular2-select',
    'angular2-datatable': 'node_modules/angular2-datatable',
    'lodash': 'npm:lodash/lodash'           <----------------HERE
    

    or

    'lodash': 'node_modules/lodash'
    

    Here is my plunker with it being imported correctly https://plnkr.co/edit/Yv7gO1eYYNIIOsoDdQrt?p=preview