Redux-persist: Uncaught SyntaxError: Unexpected token import

Created on 1 Dec 2017  路  11Comments  路  Source: rt2zz/redux-persist

Hey,buddy:
I use "redux-persist": "^5.4.0",and got this error:
import createWebStorage from './createWebStorage';
it cased "Uncaught SyntaxError: Unexpected token import"
image

Most helpful comment

@stolinski I am not sure in that case but it seems like a packaging issue. The es imports work fine in both a react-native and a webpack project I am running. FWIW importing from lib in this case has almost no downside, and in the future we will likely make it so you can import from redux-persist/storage

All 11 comments

I'm seeing the same thing here.

I am guessing you are using the readme docs which have es imports in them - they currently assume an es modules compatible environment.

Just update the import to be from lib instead of es, i.e.:

import storage from 'redux-persist/lib/storage'

I'm using it in an es modules environment with many other packages importing without issue.

thank you,buddy馃榾

@stolinski I am not sure in that case but it seems like a packaging issue. The es imports work fine in both a react-native and a webpack project I am running. FWIW importing from lib in this case has almost no downside, and in the future we will likely make it so you can import from redux-persist/storage

No worries. I've moved on to another Redux local storage package that installed and imported without issue.

I got the same problem using the redux-persist/es/storage. :-(
In addition, using the /lib/storage i have the following error:

redux-persist failed to create sync storage. falling back to memory storage.

@stolinski which local storage package have you imported?

redux-localstorage-simple

As the name suggests, it's super simple to get started.

Ok i found y it did not work. My import was shared between a server (for server side rendering) and a client. the import is correct for my client using webpack but not for the server which is not built with webpack and the lib was needed. In addition the error came from the server execution which import the storage file which try to create the local storage on the server... !!

It works now, separation has been done correctly :-)

Ah, that's def why mine wasn't working. I'm also sharing imports between client & server even though the file I was using in was client side only.

Ho ho ho ;-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benmvp picture benmvp  路  3Comments

umairfarooq44 picture umairfarooq44  路  3Comments

thenewt15 picture thenewt15  路  3Comments

openscript picture openscript  路  4Comments

peteroid picture peteroid  路  4Comments