Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatsby build always throwing Input file is missing or of an unsupported image format

Tags:

gatsby

The full description of the issue can be found here https://github.com/gatsbyjs/gatsby/issues/5638

In short, I am using gatsby-plugin-remark and gatsby-transformer-remark to optimize images placed within frontmatter of md files.

Say my markdown file has

---
title: Beautiful UI
featured_image: ../../images/project-vscbui.png
subtitle: A set of color themes for VSCode
order: 90
link: https://vscbui.rocks
templateKey: projects
---

...

And I query it like

export const projectQuery = graphql`
  query ProjectQuery {
    projects: allMarkdownRemark(
      sort: { order: DESC, fields: [frontmatter___order] }
      filter: { frontmatter: { templateKey: { eq: "projects" } } }
      limit: 1000
    ) {
      edges {
        node {
          id
          frontmatter {
            title
            subtitle
            featured_image {
              childImageSharp {
                sizes(maxWidth: 960) {
                  ...GatsbyImageSharpSizes
                }
              }
            }
            link
          }
          html
        }
      }
    }
    site {
      siteMetadata {
        shortTitle
      }
    }
  }
`;

gatsby develop works just fine. But when I run gatsby build, it fails giving errors

success Building static HTML for pages — 3.818 s
error Input file is missing or of an unsupported image format


  Error: Input file is missing or of an unsupported image format

error UNHANDLED REJECTION


  Error: Input file is missing or of an unsupported image format

Although the build actually works just fine.

To reproduce, please fork this repository https://github.com/swashata/swas.io and run yarn build. An error log can also be found here https://app.netlify.com/sites/optimistic-perlman-163196/deploys/5b10e5cdb3127429bf8a5d5d

I have tried all approach for solving this

  1. Add featured_image to every frontmatter.
  2. Remove the featured_image query from graphql.
  3. Remove the gatsby-remark-images plugin.

But nothing seems to work, except for actually removing the images and the sharp plugin.

Any help in finding the issue is very appreciated.

like image 825
Swashata Ghosh Avatar asked Jun 01 '18 06:06

Swashata Ghosh


2 Answers

It turns out I actually had a missing image file.

I am using gatsby-plugin-manifest and the image path I have put there is src/img/ninja.png, but it should have been src/images/ninja.png. I changed the directory name before and totally forgot to refactor it for the config file. I have corrected and it is working just fine.

So the bottom line is, when this error is happening

  1. Look for all image files. Especially within gatsby-config.js file.
  2. Check the output directory and see if it actually contains the "sharp"ed images.

The debugging path I took was to disable images one by one within the markdown files. But since it didn't solve the problem, I started looking elsewhere and then the gatsby-config.js came into notice. Totally my fault.

like image 50
Swashata Ghosh Avatar answered Dec 10 '22 00:12

Swashata Ghosh


For me I had the correct image and this issue was resolved by:

rm -rf node_modules
rm package-lock.json
npm cache clear --force
npm install

source: https://github.com/gatsbyjs/gatsby/issues/21515#issuecomment-588416624

like image 36
Elijah Lynn Avatar answered Dec 09 '22 23:12

Elijah Lynn