SyntaxError: Unexpected token <
Hi @chenkie
Trying to use angular2-jwt and received a Unexpected token error. My boot.ts
//<reference path="../node_modules/angular2/typings/browser.d.ts"/>
import {bootstrap} from 'angular2/platform/browser';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {AppComponent} from './app.component';
import { Http, HTTP_PROVIDERS } from 'angular2/http';
import {provide} from 'angular2/core';
import { AuthConfig, AuthHttp} from 'angular2-jwt';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
provide(AuthHttp, {
useFactory: (http) => {
return new AuthHttp(new AuthConfig({
tokenName: 'jwt'
}), http);
},
deps: [Http]
})
]);
index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Website</title>
<link rel="icon" href="assets/images/favicon.ico">
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/styles.min.css" rel="stylesheet" />
<!-- 1. Load libraries -->
<script src="libs/es6-shim.min.js" type="text/javascript"></script>
<script src="libs/system-polyfills.js" type="text/javascript"></script>
<script src="libs/shims_for_IE.js" type="text/javascript"></script>
<script src="libs/angular2-polyfills.js" type="text/javascript"></script>
<script src="libs/system.src.js" type="text/javascript"></script>
<script src="libs/Rx.js" type="text/javascript"></script>
<script src="libs/angular2.dev.js"></script>
<script src="libs/http.dev.js"></script>
<script src="libs/router.dev.js"></script>
<script src="libs/jquery.js"></script>
<script src="libs/bootstrap.js"></script>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic' rel='stylesheet' type='text/css'>
<base href="/" />
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
defaultExtension: 'js'
},
map: {
"es6-shim": "node_modules/es6-shim",
"angular2-jwt": "node_modules/angular2-jwt/angular2-jwt"
},
}
});
</script>
<script>
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
</head>
<body>
<my-app><div class="spinner"></div>Loading...</my-app>
</body>
</html>
my gulpfile.js (partial)
gulp.task('moveToLibs', function (done) {
gulp.src([
'node_modules/angular2/bundles/js',
'node_modules/angular2/bundles/angular2.*.js*',
'node_modules/angular2/bundles/angular2-polyfills.js',
'node_modules/angular2/bundles/http.*.js*',
'node_modules/angular2/bundles/router.*.js*',
'node_modules/angular2-jwt/angular2-jwt.js*',
'node_modules/es6-shim/es6-shim.min.js*',
'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
'node_modules/systemjs/dist/*.*',
'node_modules/jquery/dist/jquery.*js',
'node_modules/bootstrap/dist/js/bootstrap*.js',
'node_modules/ang-google-maps/index.js',
'node_modules/rxjs/bundles/Rx.js',
'node_modules/ng2-translate/bundles/ng2-translate.js',
'node_modules/ng2-translate/src/translate.parser.js',
'node_modules/ng2-translate/src/translate.pipe.js',
'node_modules/ng2-translate/src/translate.service.js'
]).pipe(gulp.dest('./wwwroot/libs/'));
gulp.src([
'node_modules/rxjs/**/*.js'
]).pipe(gulp.dest('./wwwroot/libs/rxjs'));
gulp.src([
'node_modules/bootstrap/dist/css/bootstrap.css',
'node_modules/components-font-awesome/css/font-awesome.css',
]).pipe(gulp.dest('./wwwroot/css'));
gulp.src([
'scripts/*.css',
'scripts/*/*.css',
])
// Combine all CSS files found inside the src directory
.pipe(concatenate('styles.min.css'))
// Minify the stylesheet
.pipe(minify())
// Report the task-execution time in the command line
.pipe(duration('Execution Time: '))
// Write the minified file in the css directory
.pipe(gulp.dest('./wwwroot/css'));
gulp.src([
'node_modules/bootstrap/fonts/glyphicons-halflings-regular.eot',
'node_modules/bootstrap/fonts/glyphicons-halflings-regular.svg',
'node_modules/bootstrap/fonts/glyphicons-halflings-regular.ttf',
'node_modules/bootstrap/fonts/glyphicons-halflings-regular.woff',
'node_modules/bootstrap/fonts/glyphicons-halflings-regular.woff2',
'node_modules/components-font-awesome/fonts/FontAwesome.otf',
'node_modules/components-font-awesome/fonts/fontawesome-webfont.eot',
'node_modules/components-font-awesome/fonts/fontawesome-webfont.svg',
'node_modules/components-font-awesome/fonts/fontawesome-webfont.ttf',
'node_modules/components-font-awesome/fonts/fontawesome-webfont.woff',
'node_modules/components-font-awesome/fonts/fontawesome-webfont.woff2',
]).pipe(gulp.dest('./wwwroot/fonts'));
gulp.src([
'scripts/*/*/*.html',
'scripts/*/*.html',
'scripts/*.html'
]).pipe(gulp.dest('./wwwroot/app'));
});
The error that I'm getting:
SyntaxError: Unexpected token < angular2-polyfills.js:390
Evaluating http://localhost:49142/angular2/platform/browser.js
Evaluating http://localhost:49142/app/boot.js
Error loading http://localhost:49142/app/boot.js
at SystemJSLoader.__exec (http://localhost:49142/libs/system.src.js:1395:16)
at entry.execute (http://localhost:49142/libs/system.src.js:3521:16)
at linkDynamicModule (http://localhost:49142/libs/system.src.js:3126:32)
at getModule (http://localhost:49142/libs/system.src.js:3094:9)
at http://localhost:49142/libs/system.src.js:3130:16
at require (http://localhost:49142/libs/system.src.js:3740:29)
at Object.eval (http://localhost:49142/app/boot.js:2:17)
at eval (http://localhost:49142/app/boot.js:25:4)
at SystemJSLoader.__exec (http://localhost:49142/libs/system.src.js:1395:16)
at entry.execute (http://localhost:49142/libs/system.src.js:3767:18)
I've tried various things such as
- changing the "angular2-jwt" path in boot.ts import { AuthConfig, AuthHttp} from 'angular2-jwt/angular2-jwt';
Received a similar error:
SyntaxError: Unexpected token < angular2-polyfills.js:390
Evaluating http://localhost:49142/angular2-jwt
Evaluating http://localhost:49142/app/boot.js
Error loading http://localhost:49142/app/boot.js
at SystemJSLoader.__exec (http://localhost:49142/libs/system.src.js:1395:16)
at entry.execute (http://localhost:49142/libs/system.src.js:3521:16)
at linkDynamicModule (http://localhost:49142/libs/system.src.js:3126:32)
at getModule (http://localhost:49142/libs/system.src.js:3094:9)
at http://localhost:49142/libs/system.src.js:3130:16
at require (http://localhost:49142/libs/system.src.js:3740:29)
at Object.eval (http://localhost:49142/app/boot.js:8:22)
at eval (http://localhost:49142/app/boot.js:25:4)
at SystemJSLoader.__exec (http://localhost:49142/libs/system.src.js:1395:16)
at entry.execute (http://localhost:49142/libs/system.src.js:3767:18)
- I also tried to modify the map config to:
map: {
"es6-shim": "node_modules/es6-shim",
"angular2-jwt": "node_modules/angular2-jwt/angular2-jwt.js"
},
- Also tried both system.src.js and system.js reference
Note: I made sure that cleared the cached images & files in Chrome. I'm using Gulp to move my the 3rd party js libraries, fonts, css via Gulp. I'm using VS 2015.
Any other things i should try to get it to work?
@escardin @chenkie - I'm getting the same issue as well. Do you have any suggestions?
Can you try bringing the map key outside of packages?
System.config({
defaultJSExtensions: true,
packages: {
app: {
format: 'register',
defaultExtension: 'js'
},
"angular2-jwt": {
defaultExtension: 'js'
}
},
map: {
"angular2-jwt": "node_modules/angular2-jwt/angular2-jwt.js"
}
});
@chenkie I changed it to that, however, with the defaultJSExtensions I get 'require is not defined'. Taking that out gives me the same error above.
I also noticed that when I'm in chrome dev tools and I click on the jwt file, it shows the index.html

When I tried to move the map key outside of the packages (plus add the defaultJSExtensions and format register), I get a different error:
ReferenceError: require is not defined angular2-polyfills.js:390
Evaluating http://localhost:49142/app/boot.js
Error loading http://localhost:49142/app/boot.js
So i just the map key outside of the packages and it's the same error that I received above.
Note: I changed the map directly to the js file name "angular2-jwt": "node_modules/angular2-jwt/angular2-jwt.js" as well.
Hi @chenkie
I tried different combinations of the path and was able to get mine to work. Basically my index.html file resides in an app folder, but my angular2-jwt.js resides in the lib folder. So my folder structure: MyWebProj
- wwwroot/
- app/
- libs/
- index.html
- scripts/
- node_modules/
- package.json
- gulpfile.js
I slightly modified your suggestion and pointed it to my libs folder.
index.html
<script>
System.config({
packages: {
app: {
defaultExtension: 'js'
},
"angular2-jwt": {
defaultExtension: 'js'
}
},
map: {
"es6-shim": "node_modules/es6-shim",
"angular2-jwt": "../libs/angular2-jwt.js"
}
});
</script>
Thanks for your help on this! I appreciate it!
Glad you got it :)
@dasis and @chenkie Thanks for your contribution, you have helped me, at least the application runs, now the console shows me the following:

I would like to know if you know what the problem is.
Thank you!
@santiim please push your code to a gist or a repo we can take a look at, and open a new issue. Also your problem is a config issue and likely not specific to this library.
@escardin Thank you very much for your prompt response! here is the project uploaded to github: https://github.com/santiim/angular2-angular2-jwt-
Thank you very much for your help!!
