use-hooks/react-hooks-axios

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

pkellner opened this issue · 7 comments

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

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.

Thanks

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.

@dlbnco reopened and look for more feedback

same problem

It may be related with this axios/axios#244

same problem