angular2-localstorage icon indicating copy to clipboard operation
angular2-localstorage copied to clipboard

"Module parse failed" when including LocalStorageService in bootstrap.ts

Open mark-norgate opened this issue 9 years ago • 5 comments

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,

mark-norgate avatar Jun 13 '16 10:06 mark-norgate

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.

marcj avatar Jun 13 '16 13:06 marcj

Sio why am I getting the Module parse failed error?

mark-norgate avatar Jun 13 '16 13:06 mark-norgate

I have no idea.

marcj avatar Jun 13 '16 13:06 marcj

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.

SDohle avatar Jun 16 '16 06:06 SDohle

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'
  ]
},

ailinykh avatar Jul 23 '16 21:07 ailinykh