Home

Gatsby Error - field type "String" - working with images

Problem

While working with images in frontmatter using Gatsby, I got the following error:

Field "cover" must not have a selection since type "String" has no subfields.

This can happen if you e.g. accidentally added { } to the field "cover". If you didn't expect "cover" to be of type "String" make sure that your input source and/or plugin is correct.

Explanation

I have stuck with this error for almost an hour, this looks like a weird error because it won't appears often.

Solution

Finally after experimenting a lot, I have found that, if I changed the property in frontmatter, then I am getting the desired output.

It means that when I changed the word cover to coverImage, then I am not getting any error and I was able to get the image from the frontmatter.

The cause of this error is the inconsistency in the frontmatter of my markdown files. In some files I was using an array, and a single value in other. So when I fixed this, the error disappeared.

I haven't got any proof for my solution, even in the Gatsby docs. I have just arrived at this solution be trial and error.



Last Updated on

Next Post: Rules vs Guidelines →

Comments