Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using without explicitly passing a storage engine is throwing an error with Webpack/Browserify #3

Closed
ekryski opened this issue Feb 28, 2016 · 6 comments
Labels
bug

Comments

@ekryski
Copy link
Member

@ekryski ekryski commented Feb 28, 2016

@naptiv reported this in feathersjs-ecosystem/authentication#84:

Btw, I had to change .use('storage', localstorage({"storage":memory})) as I got a ReferenceError: window is not defined at new LocalStorage @feathers-localstorage/lib/index.js:32:41

@ekryski ekryski added the bug label Feb 28, 2016
@ekryski

This comment has been minimized.

Copy link
Member Author

@ekryski ekryski commented Feb 28, 2016

@naptiv are you using webpack or babel? I'm wondering if it is a shimming issue.

Maybe we shouldn't be expecting window to just be there and instead you always get the developer to pass in their storage engine explicitly. cc/ @daffl

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Feb 28, 2016

@ekryski

This comment has been minimized.

Copy link
Member Author

@ekryski ekryski commented Feb 28, 2016

Ya the issue is that with webpack you need to shim the window object. So you end up with something like this in your config.

externals: [
        {
            "window": "window"
        }
    ],

Not sure how I want to proceed here. I think it actually might be more flexible and work "out of the box" better if we explicitly get people to pass in their storage engine. Less magic.

@ekryski ekryski changed the title Using without explicitly passing a storage engine is throwing an error Using without explicitly passing a storage engine is throwing an error with Webpack/Browserify Feb 28, 2016
@daffl

This comment has been minimized.

Copy link
Member

@daffl daffl commented Feb 28, 2016

We should probably also set https://github.com/feathersjs/feathers-localstorage/blob/master/src/index.js#L7 to

this._storage = options.storage || (typeof window !== 'undefined' && window.localStorage);
@daffl

This comment has been minimized.

Copy link
Member

@daffl daffl commented Feb 28, 2016

And then throw an error if this._storage is still undefined.

@ekryski

This comment has been minimized.

Copy link
Member Author

@ekryski ekryski commented Feb 28, 2016

Ya I think you're right @daffl

@ekryski ekryski closed this in 72e4a99 Feb 28, 2016
ekryski added a commit that referenced this issue Feb 28, 2016
throw an error if storage is not passed in explicitly. Closes #3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.