-
Notifications
You must be signed in to change notification settings - Fork 493
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
TypeError: Cannot read property 'localStorage' of undefined #744
Comments
also ran into this issue. we're loading a universal js app (nuxt.js) and its happening when importing the 'auth0-js' library. The reason is that the auth0-js module is itself trying to instantiate a StorageHandler, and there is no window object on the server. think that this should be refactored: auth0.js/src/helper/storage.js Line 2 in dcf7138
to just define functions, but not actually run the code that depends upon the window object |
Auth0.js is meant to be used only inside the browser. If you are running a server rendered application, make sure to only instantiate Auth0.js objects when you're running in the browser. For react, for example, make sure to always instantiate objects in the |
@luisrudge actually the issue is a little more subtle than that Re: In my case, we are only running the actual call to In the particular universal js framework we are using (nuxt.js) imports are done as part of pre-processing bundling, and so the same libraries are loaded on the browser and client. Loading a module should not result in the execution of code. Rather, executing the functions defined in a module should execute code. see auth0.js/src/helper/storage.js Line 2 in dcf7138
which is running code upon module load. |
also note that this error only started appearing in version 9.5.0 of auth0-js |
@luisrudge I made #745 to fix this. |
@phlogisticfugu you're totally right. I'll fix this in a different PR, since we don't want to have that lazy thing again, but thanks for figuring out the issue! |
I installed auth0-js ( version 9.5.0 ) in node application.
Node version is 6.9.0.
I got the issue after launching application with npm start.
TypeError: Cannot read property 'localStorage' of undefined
....
Can't use localStorage. Using CookieStorage instead.
How can I resolve it?
The text was updated successfully, but these errors were encountered: