question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pathPrefix in gatsby-config is not prepending the prefix to assets.

See original GitHub issue

Hello everyone. I’m trying to deploy my gatsby project on a sub-directory like: https://www.example.com/blog

Following the docs, I added a /blog path prefix into my gatsby-config.js file. Then, I build the project using the command gatsby build --prefix-paths

When i check my generated index.html in my public folder, i’m seeing that the prefix is not prepended to the statics assets’ path.

I’ve started from a fresh project and yet I am still having the issue. Maybe I’ve been looking at it for too long and missing something stupid. I’ve also tried double quotes, simple quotes, removing the leading slash, but nothing seems to work. Any help would be appreciated.

Steps to reproduce

  1. Start a new project : gatsby new gatsby-site
  2. Add a pathPrefix into gatsby-config.js :
  siteMetadata: {
    pathPrefix: `/blog`,
  },
  1. Build the project using the flag : gatsby build --prefix-paths
  2. Check the presence of the prefix you chose in the assets linked in the index.html file

Expected result

Linked static assets prepended with the path prefix should be like : src="/blog/static/6d91c86c0fde632ba4cd01062fd9ccfa/630fb/gatsby-astronaut.png"

Actual result

src="/static/6d91c86c0fde632ba4cd01062fd9ccfa/630fb/gatsby-astronaut.png"

Environment

System: OS: Windows 10 10.0.18362 CPU: (4) x64 Intel® Core™ i5-6600K CPU @ 3.50GHz Binaries: Node: 12.5.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD Languages: Python: 2.7.16 - /c/Python27/python Browsers: Edge: 44.18362.449.0 npmPackages: gatsby: ^2.21.37 => 2.21.37 gatsby-image: ^2.4.4 => 2.4.4 gatsby-plugin-manifest: ^2.4.5 => 2.4.5 gatsby-plugin-offline: ^3.2.3 => 3.2.3 gatsby-plugin-react-helmet: ^3.3.1 => 3.3.1 gatsby-plugin-sharp: ^2.6.4 => 2.6.4 gatsby-source-filesystem: ^2.3.4 => 2.3.4 gatsby-transformer-sharp: ^2.5.2 => 2.5.2 npmGlobalPackages: gatsby-cli: 2.11.8

gatsby-config.js

module.exports = {
  siteMetadata: {
    pathPrefix: `/blog`,
    title: `Gatsby Default Starter`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `.`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.dev/offline
    // `gatsby-plugin-offline`,
  ],
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
thomascorthoutscommented, May 27, 2020

Hi @RebootGG

Could you try moving your pathPrefix: '/blog', from the siteMetadata to 1 level up and see if that works, the docs say it needs to be in the root level of the object put in module.exports for it to work

0reactions
airtonixcommented, Oct 9, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding a Path Prefix
By using the Gatsby Link component, paths will automatically be prefixed with the pathPrefix value assigned in your gatsby-config.js file. If you later...
Read more >
Adding a Path Prefix | GatsbyJS - Netlify
Let's get this functionality implemented. We'll add an option to our gatsby-config.js , and add a flag to our build command.
Read more >
Gatsby: is there any way to add a prefix path to the assets ...
Because in my development environment I would like to have (almost) the same configuration I've in prod where I can set assetPrefix and ......
Read more >
Gatsby build : files not found / Failed to load resource
Then, go to your gatsby-config.js file, and add the location of a server where you ... At the top of the module.exports, add...
Read more >
Base Path - next.config.js
To deploy a Next.js application under a sub-path of a domain you can use the basePath config option. basePath allows you to set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found