Closed stevanpopo closed 4 years ago
Does it make a difference that I'm resolving images from multiple locations?
gatsby-config.js
module.exports = {
siteMetadata: {
title: `codewithbootcamps.com`,
author: `Stevan Popovic`,
description: `Find, compare and choose the best coding bootcamp in London and kick-start your switch to a career in software development.`,
siteUrl: `https://www.codewithbootcamps.com/`,
},
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/content/brands`,
name: `brands`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/content/blog`,
name: `blog`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/content/assets`,
name: `assets`,
},
},
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 740,
wrapperStyle: `margin-bottom: 2.2rem;`,
},
},
{
resolve: `gatsby-remark-responsive-iframe`,
options: {
wrapperStyle: `margin-bottom: 2.2rem;`,
},
},
`gatsby-remark-prismjs`,
`gatsby-remark-copy-linked-files`,
`gatsby-remark-smartypants`,
],
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: `UA-148403702-1`,
},
},
`gatsby-plugin-feed`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `Gatsby Starter Blog`,
short_name: `GatsbyJS`,
start_url: `/`,
background_color: `#ffffff`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `content/assets/favicon-32x32.png`,
},
},
`gatsby-plugin-offline`,
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-plugin-typography`,
options: {
pathToConfigModule: `src/utils/typography`,
},
},
`gatsby-plugin-sass`,
`gatsby-plugin-sitemap`,
`gatsby-plugin-twitter`,
`gatsby-plugin-force-trailing-slashes`,
],
}
@stevanpopo i saw that you mentioned me in another issue that might be related to this. If you don't mind waiting a bit i'll see what is wrong and come back with a response, sounds good?
@jonniebigodes yep, sounds good. I saw you answered something relevant when I was digging through other issues, so thought you might have some insight here.
It looks like for some reason gatsby-transformer-sharp isn't turning my file paths into file objects.
Hi!
Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.
If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.
Thanks for using Gatsby! 💜
@stevanpopo i've been through this and i think i have a solution for you.
I'm going to describe the steps and what i believe is the cause of the issue.
gatsby-config.js
to match yours.src\blog\bootcamps
called index.md with the following content:
---
title: "How To Choose The Right Coding Bootcamp"
featuredImage: ./codebootcamps.jpg
---
This is some dummy content to illustrate something something
- Copied over a dummy image to the folder and make both files "siblings".
- Ran `gatsby develop` and the build goes through without any issue.
- Ran `gatsby clean` to get a clean slate and then issued `gatsby build && gatsby serve` and i'm presented with the issue.
- Went back to development mode and opened `http://localhost:8000/___graphql` ran the query and i'm presented with the following:
![stevan_popo1](https://user-images.githubusercontent.com/22988955/72174072-cb956080-33d0-11ea-9b7f-f27965600faa.png)
- Updated the query in the template file to:
```graphql
query BlogPostBySlug($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
id
excerpt(pruneLength: 160)
html
frontmatter {
title
date(formatString: "MMMM DD, YYYY")
description
featuredImage {
childImageSharp {
fluid(maxWidth: 630) {
...GatsbyImageSharpFluid
}
}
}
}
}
}
Opened the blog post i mentioned earlier and i'm presented with:
Ran gatsby clean
to once again get a clean slate and ran once again gatsby build && gatsby serve
, the build goes through and opening up http://localhost:9000/bootcamps/
i'm presented with the image and content without any issues.
What i would like for you to do is update the query and trigger a build to see if the issue is resolved, if not it could probably be a good thing to create a minimal reproduction like @LekoArts mentioned so that we can take a more detailed look at what might be causing this issue. Sounds good?
@jonniebigodes thank you so much for taking the time to write this detailed response. I must apologise though, as I have wasted your time. On second look, I found the error and it was completely my fault. On one of the posts, I had a typo in the file path, meaning the file wasn't found, turning all of them into strings, rather than file objects. Completely my error. Thanks again for helping anyway.
@stevanpopo no need to thank, Glad to know that you managed to solve your issue. And it was no problem writing the response.
anyone knows how or who is automatically chosing to convert to an object or a string? I find it a bit fragile that if any field in the frontmatter matches a file path is converted to an image, but if not, is just a string.
Description
I have added an image to a blog post (via frontmatter) that I am trying to access via a GraphQL query but fails on the build.
Code
My frontmatter
Note - This frontmatter exists in an index.md file which is a sibling to the image. post_folder --> index.md --> codebootcamps.jpg
My query
Expected result
Image path to be available in blog post on render.
Actual result
The build fails with this error: GraphQL Error Field "featuredImage" must not have a selection since type "String" has no subfields.
This result is confirmed when I view in GraphiQL.
Environment
I have both
gatsby-transformer-sharp
andgatsby-plugin-sharp
installed.Thanks for any help in advance. I appreciate your time.