Common build errors
While working on our project, we mostly run the project in development mode. This is a great idea to ensure that the site also works with a production build by running the gatsby build
command.
Sometimes, you might find that errors occur during the build process. So, let's talk about the most common issues and how we can fix them:
- The most common error that you'll come across is window/document is not defined. Node.js does not contain the
window
anddocument
variables found in the browser. Therefore, while your site is being built, it is unable to access them. You can get around this issue in a couple of ways. You can perform a check to confirm that the variable is defined (for example,typeof window !== undefined && yourFunction()
), or if appropriate, you can move the code into auseEffect
hook. - Ensure that all your components, your pages, and your
gatsby-browser.js
andgatsby-ssr.js
files do not mix ES5 and ES6 syntax, as this...