As I dive into developing a basic Angular 2 application that utilizes a CommonJS Node module (Node Yelp), I find myself facing challenges with SystemJS, the default loader used by Angular 2. SystemJS has the capability to handle various module formats.
Despite experimenting with different SystemJS setups and import statements, I keep encountering the same error:
SyntaxError: Unexpected token <(…)
My current SystemJS configuration appears as follows:
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
},
map: {
yelp: 'node_modules/yelp'
}
});
System.import('app/main')
.then(null, console.error.bind(console));
Alongside my simple AppComponent.ts
:
import {Component} from 'angular2/core';
import Yelp from 'yelp';
@Component({
selector: 'app',
templateUrl: '/app/app.component.html'
})
export class AppComponent {
constructor(yelp: Yelp) {
console.log(yelp);
}
}
Grasping the entire module system is still a work in progress for me, making it unclear what changes are required here. Most online resources I've come across are either outdated or not directly addressing the loading of CommonJS node modules with SystemJS.