导入第 3 方库时的 systemJS "unexpected token error"
systemJS "unexpected token error" when importing 3rd party library
我正在尝试在 angular2 应用程序中使用 angular2-datatable
但是在将导入放入 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'
这是我的插件,已正确导入
https://plnkr.co/edit/Yv7gO1eYYNIIOsoDdQrt?p=preview
我正在尝试在 angular2 应用程序中使用 angular2-datatable 但是在将导入放入 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'
这是我的插件,已正确导入 https://plnkr.co/edit/Yv7gO1eYYNIIOsoDdQrt?p=preview