0

I'm getting the following error inside my Gatsby with Sanity app on running npm run build:

 WebpackError: ReferenceError: window is not defined (from plugin: gatsby-plugi
  n-styled-components)

Seems to be that the external package gatsby-plugin-styled-components is using window somewhere.I've tried replacing by a dummy module as described here https://www.gatsbyjs.com/docs/debugging-html-builds/#fixing-third-party-modules except my styled-components does not work then so it is not a solution.

Perhaps I'm using styled component techniques where are not supported? I've looked at different gatsby/styled components example repo's and cannot find the difference.

You can find the repo here: https://github.com/sanderdebr/sanity-gatsby-portfolio

sanderdebr
  • 120
  • 3
  • 8

1 Answers1

0

This is because your project or the gatsby-plugin-styled-components is using somewhere styled-components@5.2.2 which is a broken version using window.

The issue has been tracked on SC Github: https://github.com/styled-components/styled-components/issues/3444

I recommend you to update to styled-components@5.2.3

pascaloliv
  • 18
  • 2