我试图在Angular2应用但是在AppModule中输入导入后,我在尝试运行应用程序时会遇到以下错误
Error: (SystemJS) Unexpected token <
这是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 { }
这是我的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);
我以相同的方式导入其他库,因此我不确定我缺少什么。有任何想法吗?
看起来您需要确保系统JS中也引用了lodash
。尝试添加此...
'angular2-select': 'node_modules/angular2-select',
'angular2-datatable': 'node_modules/angular2-datatable',
'lodash': 'npm:lodash/lodash' <----------------HERE
或
'lodash': 'node_modules/lodash'
这是我的plunker,它的进口正确https://plnkr.co/edit/yv7go1eyyniiosoddqrt?p=preview