react-hooks-axios icon indicating copy to clipboard operation
react-hooks-axios copied to clipboard

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

Open pkellner opened this issue 6 years ago • 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

pkellner avatar Apr 07 '19 22:04 pkellner

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.

int64ago avatar Apr 09 '19 12:04 int64ago

Thanks

pkellner avatar Apr 09 '19 13:04 pkellner

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 avatar Sep 10 '19 09:09 dlbnco

@dlbnco reopened and look for more feedback

int64ago avatar Sep 10 '19 13:09 int64ago

same problem

jzhu1224 avatar Sep 19 '19 22:09 jzhu1224

It may be related with this https://github.com/axios/axios/issues/244

int64ago avatar Oct 23 '19 01:10 int64ago

same problem

daviddang91 avatar Dec 19 '19 03:12 daviddang91