I deployed a gatsby website with the Github pages and I'm having errors like that: Locally everything works perfectly, errors occur only on the server. Seems like the server can not resolve paths correctly. I'm adding unnecessary repository name after domain. How to remove that? I tried changing some host options and deploying app again and once it worked properly, IDK why, then I made another deploy and it crushed again. My gatsby.config:
const path = require("path");
const { title, keywords, description, author, defaultLang, trackingId } = require("./config/site");
module.exports = {
pathPrefix: "/lbearthworks",
siteMetadata: {
title,
keywords,
description,
author,
},
plugins: [
{
resolve: "gatsby-plugin-google-analytics",
options: {
trackingId,
},
},
{
resolve: "gatsby-plugin-manifest",
options: {
name: title,
short_name: "Lb",
start_url: "/",
background_color: "#212121",
theme_color: "#fed136",
display: "minimal-ui",
icon: "content/assets/gatsby-icon.png",
},
},
"gatsby-transformer-remark",
{
resolve: "gatsby-source-filesystem",
options: {
name: "markdown",
path: `${__dirname}/content`,
},
},
{
resolve: "gatsby-source-filesystem",
options: {
name: "images",
path: `${__dirname}/content/assets/images`,
},
},
"gatsby-plugin-eslint",
"gatsby-plugin-react-helmet",
"gatsby-transformer-sharp",
"gatsby-plugin-sharp",
"gatsby-plugin-offline",
{
resolve: "gatsby-plugin-sass",
options: {
data: `@import "core.scss";`,
includePaths: [path.resolve(__dirname, "src/style")],
},
},
...
],
};
When dealing with GitHub Pages you need to add an extra configuration to your build command, since you are adding a
pathPrefix
variable, you need to allow Netlify how to prefix those paths. Ideally, the build command should look like:In your case, because you are adding a file-based configuration (
netlify.toml
), your build command is:Note that
testbuild
isyarn test && yarn build
, according to your repository.So, one workaround is changing your
package.json
command to:In addition, you should be in
gh-pages
branch as it shows the Gatsby's documentation: