leebenson / reactql

Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
https://reactql.org
MIT License
1.82k stars 173 forks source link

import third party package has error: window is not defined #120

Closed ryanyu104 closed 6 years ago

ryanyu104 commented 6 years ago

when I import plugin in my project code: import ReactMic from "react-mic" report error: window is not defined.

I know it is the server environment, but how can I solve this error? THX

klarstrup commented 6 years ago

The problem is in the react-mic codebase: https://github.com/hackingbeauty/react-mic/blob/3edd1e9a651a0afdd35aaed23e33449fec6eb0b1/src/libs/AudioContext.js#L1

Here there is unguarded access to the window global at the top level. Which means that as long as react-mic is imported anywhere, it'll break the server whether used at all at runtime or not. You'll need to submit a PR to react-mic to fix this.

ryanyu104 commented 6 years ago

@klarstrup THX, I get it. I will close this issue.