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 global "window" causing server-side to blow up #17

Open
pkellner opened this issue Apr 7, 2019 · 7 comments
Open

using global "window" causing server-side to blow up #17

pkellner opened this issue Apr 7, 2019 · 7 comments

Comments

@pkellner
Copy link

pkellner commented Apr 7, 2019

I use the next.js framework and like other SSR frameworks, builds the app in node. I'm getting the error I'm pasting below from "I have no idea where" but I think it might be inside react-hooks-axios using the window object. Is that possible. Feel free to close right away if this isn't the case and sorry for the trouble.

ReferenceError: window is not defined
at Object. (/Users/peterkellner/Documents/pluralsight-course-using-react-hooks/05-Combing-React-Hooks-REST-Example/_experimental/M3-clip10-useMemo-to-Cache-Speaker-Sorted-Data/node_modules/
use-hooks/axios/dist/index.js:1:361
Module._compile
internal/modules/cjs/loader.js:689:30
Module._extensions..js
internal/modules/cjs/loader.js:700:10
Module.load
internal/modules/cjs/loader.js:599:32
tryModuleLoad
internal/modules/cjs/loader.js:538:12
Function.Module._load
internal/modules/cjs/loader.js:530:3
Module.require
internal/modules/cjs/loader.js:637:17
require
internal/modules/cjs/helpers.js:22:18
@use-hooks/axios
webpack:/external "@use-hooks/axios":1

@int64ago
Copy link
Member

int64ago commented Apr 9, 2019

Hi, I have no idea for this, there's no DOM-related things used in this package, it seems like the feature of axios, but there's no more information to dig out the reason.

@pkellner
Copy link
Author

pkellner commented Apr 9, 2019

Thanks

@pkellner pkellner closed this as completed Apr 9, 2019
@dlbnco
Copy link

dlbnco commented Sep 10, 2019

I had the same problem while working with Gatsby. Checking for window before declaring useAxios worked. I'm building a custom hook, so it looks like this:

if (typeof window !== 'undefined') {
    const useAxios = require('@use-hooks/axios');
    return useAxios.default({
      // ...
    })
}

For some reason, I had to call useAxios.default instead of just useAxios.

@int64ago
Copy link
Member

@dlbnco reopened and look for more feedback

@int64ago int64ago reopened this Sep 10, 2019
@jzhu1224
Copy link

same problem

@int64ago
Copy link
Member

It may be related with this axios/axios#244

@daviddang91
Copy link

same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants