4

I'm attempting to use inline images in my markdown file using gatsby-remark-images. Unfortunately, the image won't load on my local host. I don't know if it's simply erroneous syntax or I am missing something drastic.

Here's the config: (I have a suspicion that I've done something wrong somewhere, it's here.)

module.exports = {
  siteMetadata: {
    title: ``,
    description: `A blog where code is written about`,
    author: `@wesley`,
  },

  plugins: [
    `gatsby-plugin-sass`,
    `gatsby-plugin-styled-components`,
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-catch-links`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/src/images`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/src/pages`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          {
            resolve: `gatsby-remark-images`,
            options: {
              // It's important to specify the maxWidth (in pixels) of
              // the content container as this plugin uses this as the
              // base for generating different widths of each image.
              maxWidth: 1200,
            },
          },
        ],
      },
    },

    `gatsby-transformer-remark`,
    {
      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/mt.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`,
  ],
};

I've pored over the poor documentation on Gatsby over and over. I am confounded. Anyone have an idea as to what's going on? I was able to get the featured image to work, but that's not what I want.

package.json: here's the json package

Path in markdown file is right (I believe): path is right (i believe)

Screenshot of what I'm getting: but this is what i'm getting

AWolf
  • 8,770
  • 5
  • 33
  • 39
  • 2
    welcome to SO. Please copy/paste your text instead of using screenshots when possible. 1- better accessibility 2- easier SEO – Félix Paradis Nov 19 '19 at 19:33

1 Answers1

6

I think if you remove the following line from your Gatsby config it will work.

Gatsby config is using that line instead of the previously defined configuration. That's why gatsby-remark-images plugin is not used.

Your relative path in the markdown file is right with ../../images/train.png.

Extracted lines from your config:

module.exports = {
 plugins: [
    // ... other plugins
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          {
            resolve: `gatsby-remark-images`,
            options: {
              // It's important to specify the maxWidth (in pixels) of
              // the content container as this plugin uses this as the
              // base for generating different widths of each image.
              maxWidth: 1200,
            },
          },
        ],
      },
    },

    // `gatsby-transformer-remark`, // remove this as it will override previous configuration 
   ]
};

Screenshot of the loaded image: train image

AWolf
  • 8,770
  • 5
  • 33
  • 39
  • wow that totally solved my problem, thanks! I'd recently added support for embedded youtube videos, and didn't realise I'd now added a 2nd `gatsby-transformer-remark` – Hilton Giesenow Dec 01 '20 at 15:56
  • 2
    I understand this isn't the best use of a comment, but this answer saved me from hours of confusing investigation. Much appreciated. – bearplane Apr 26 '21 at 03:07