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

Error importing into gatsby #105

Open
tractorcow opened this issue Jun 13, 2022 · 1 comment
Open

Error importing into gatsby #105

tractorcow opened this issue Jun 13, 2022 · 1 comment

Comments

@tractorcow
Copy link

When embedding this component into gatsby, we have an error on window definition.

https://github.com/farminf/pannellum-react/blob/master/src/pannellum/js/libpannellum.js#L24

This triggers the below

WebpackError: ReferenceError: window is not defined

As we only render the component on client side, it's not necessary that we actually render on the serverside, only that the module itself doesn't crash compilation.

We can probably work around by using a conditional import on the panellum-react module, but ideally the window.libpannellum assignment would be wrapped in an if (typeof window !== 'undefined')

@tractorcow
Copy link
Author

FYI this is my temporary workaround.

import type { PannellumVideo as PannellumVideoType } from "pannellum-react/lib/index"
let PannellumVideo: typeof PannellumVideoType
if (typeof window === "undefined") {
  PannellumVideo = () => <div />
} else {
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  const imported = require("pannellum-react")
  PannellumVideo = imported.PannellumVideo
}

export { PannellumVideo }

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

1 participant