"Module parse failed" when including LocalStorageService in bootstrap.ts
I am receiving errors when I add LocalStorageService to my bootstrap code. One of the errors I receive looks like this:
Module parse failed: /node_modules/angular2-localstorage/LocalStorageEmitter.ts Unexpected token (6:14)
I am adding this in my bootstrap.ts:
import {LocalStorageService, LocalStorageSubscriber} from 'angular2-localstorage/LocalStorageEmitter';
var appPromise = bootstrap(AppComponent, [ LocalStorageService,
ROUTER_PROVIDERS, HTTP_BINDINGS, servicesInjectables,
provide(LocationStrategy, {useClass: HashLocationStrategy})
]);
LocalStorageSubscriber(appPromise);
There are similar errors for LocalStoageEmitter.ts. I thought it might be an issue with TypeScript not compiling these .ts files, but there is a tsconfig.json in the module folder - do I need to do anything special to get these to compile? I am using webpack. I notice there are no corresponding .js files.
Any help appreciated,
do I need to do anything special to get these to compile
No, since you already have a bootstrap.ts which should be compiled by your build scripts.
Sio why am I getting the Module parse failed error?
I have no idea.
I have a similar problem when using UglifyJs: ERROR in vendor.js from UglifyJs Unexpected token: string (./WebStorage) [./~/angular2-localstorage/index.js:1,0]
It works without ugifying.
In my case that error occures because of there are no compiled version in repo (see #28).
I am using webpack and it configured to not compile .ts files from node_modules by default.
So for quick fix you can use a little bit more extended configuration of webpack
{
test: /\.ts$/,
exclude: /node_modules\/(?!(angular2-localstorage)\/).*/,
loaders: [
'ts'
]
},