-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gatsby Image - Unknown fragment ... #20984
Comments
We are seeing a similar issue using fragments from
Environment
|
Can you please upgrade to |
@vladar Thanks for your input. I've tested, without success the following Gatsby versions:
However, I have a local, a staging and a production site which all built just fine with the exact same code base on 2.19.8 a couple of weeks or so ago and when I got back at it earlier today (still on 2.19.8) I got the error I'm reporting here. |
This sounds very weird. I'd very much appreciate if you could provide a minimal reproduction. Or if you have a private project - you can invite me there and I will check. It is hard to help without some code to look at. |
@vladar I'm running into what I believe to be a similar issue. That said, I'm receiving it on other fragments that I've created, as seen below. I'll work to get more information. Versions:Known Working Gatsby Versions:
Known Failing Gatsby Versions:
2.19.8 Changelog:Bug Fixes
Performance Improvements
Following The Issue:
|
How can I reach out ? |
I am also getting the same/similar error as @tmilewski but some additional weirdness is that it happens while editing seemingly unrelated code (such as removing a className from an element and then saving) and having the hot-module-loader automatically refresh my browser. Either making another change to my code and then saving or running "gatsby develop" rebuilds the site/app correctly without any errors. I have also gotten this error with the same Gatsby project hosted on Netlify and manually triggering another deploy right after also built the site/app correctly without any errors. The error I get:
This above is all one error message. |
We've published a canary of a potential fix for this issue in Please try it out and let us know if it fixes it for you! 🙌 |
@sidharthachatterjee I can confirm that the fix published in Thank you team for such a quick response and resolution ! |
I am experiencing this issue as well, getting the error:
I can confirm that using the fix in The one difference that stands out to me in the case of where it's still occuring is that the fragments are nested within other fragments. I.e. I have an |
@afladmark Interesting. Do you happen to have a minimal reproduction of this? It'll help us knock out edge cases and get this fix shipped. |
@sidharthachatterjee This looks to work for me! Thank you for the fast fix! @afladmark Did you |
So, this is super odd. I spoke too soon.
|
As we source our data from a Contentful account, I'm not sure how best to provide you a minimal reproduction. I can provide some insight into the queries we're using as a starting point. In the page template we have a page query:
And then the Asset fragment is defined as:
If I replace both usages of the I then reverted to 2.19.10 and did The only thing I can't as yet explain is that I have other fragments very much like this one which are in use and are not causing this issue. :-( I may be able to provide access to the repo, privately. Or if you can suggest how best to approach replicating the Contentful setup in a minimal reproduction I can have a go at it. |
Hmm. The only different between the Asset fragment and the other similar ones is that it's a fragment based on Further hmmmm.... It's only two usages of the |
The hot-fix we came up is indeed not reliable - it worked for reproduction we had, but this was probably incidental :( We still need reproductions here folks! Specifically ones that still fail after trying test gatsby version that @sidharthachatterjee posted |
Updating gatsby from |
The bug was in fragment cycle detection (in an edge case when the same fragment was referenced multiple times within one query and then also referenced in another query). The caveat though is that the error was reported on the next fragment usage in another query (sometimes seemingly innocent). That's why it was so hard to reproduce. #21128 should fix it (hopefully) @Coriou thanks a lot for repro access! |
Thanks to @vladar this was fixed in Thank you everyone! |
Hopefully fixed 😅 At least should be fixed for the original issue description (as I was able to test on this repo). But if someone encounters a similar error, please open a new issue with your details (and ideally - reproduction) |
Thank you so much for quickly attacking this! I can 100% confirm that |
Also confirmed. Everything is building fine again. Thank you very much for the fix! |
I run into this and now could fix the issue. It was either one of these:
|
I can confirm about @axe312ger that no two static queries should have the same name. |
I'm encountering this same issue.
|
@carlaiau Hmm, I don't think it's that issue. I have images in Contentful, have cleared my cache and reinstalled the dependencies multiple times to no avail. |
Hi guys. I have the same problems. I tried to use version I put the following code on my gatsby-node.js: const path = require(`path`);
const { createFilePath } = require(`gatsby-source-filesystem`);
const { fmImagesToRelative } = require(`gatsby-remark-relative-images`);
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
fmImagesToRelative(node);
if (node.internal.type === `MarkdownRemark`) {
const slug = createFilePath({
node,
getNode,
basePath: `pages`,
});
createNodeField({
name: `slug`,
node,
value: `/${slug.slice(12)}`,
});
}
};
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
return graphql(`
{
allMarkdownRemark(sort: { order: DESC, fields: frontmatter___date }) {
edges {
node {
fields {
slug
}
frontmatter {
category
date(locale: "pt-br", formatString: "DD[/]MM[/]YYYY")
description
featuredImage {
childImageSharp {
fluid(maxWidth: 960) {
...GatsbyImageSharpFluid
}
}
}
title
}
timeToRead
}
}
}
}
`).then((result) => {
const posts = result.data.allMarkdownRemark.edges;
// Create posts
posts.forEach(({ node }) => {
createPage({
path: node.fields.slug,
component: path.resolve('./src/templates/blog-post/index.js'),
context: {
slug: node.fields.slug,
},
});
});
});
}; Before I put the code ERROR #85922 GRAPHQL
There was an error in your GraphQL query:
Field "featuredImage" must not have a selection since type "String" has no subfields.
This can happen if you e.g. accidentally added { } to the field "featuredImage". If you didn't expect "featuredImage" to be of type "String" make sure that your input source and/or plugin is correct.
File: gatsby-node.js:26:10 Now, after I put both code lines, the console returns the following error: ERROR #85901 GRAPHQL
There was an error in your GraphQL query:
Unknown fragment "GatsbyImageSharpFluid".
File: gatsby-node.js:28:10 My dependencies on package.json: {
"dependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"algoliasearch": "^4.2.0",
"babel-jest": "^26.0.1",
"babel-plugin-styled-components": "^1.10.7",
"commitizen": "^4.1.2",
"cz-conventional-changelog": "^3.2.0",
"dotenv": "^8.2.0",
"gatsby-image": "^2.4.4",
"gatsby-plugin-algolia-search": "0.5.7",
"gatsby-plugin-manifest": "^2.4.6",
"gatsby-plugin-offline": "^3.2.4",
"gatsby-plugin-react-helmet": "^3.3.1",
"gatsby-plugin-sharp": "^2.6.6",
"gatsby-plugin-sitemap": "^2.4.2",
"gatsby-plugin-styled-components": "^3.3.1",
"gatsby-plugin-transition-link": "^1.18.0",
"gatsby-remark-images": "^3.3.5",
"gatsby-remark-lazy-load": "^1.0.2",
"gatsby-remark-prismjs": "^3.5.1",
"gatsby-remark-relative-images": "^0.2.3",
"gatsby-source-filesystem": "^2.3.5",
"gatsby-transformer-remark": "^2.8.10",
"gatsby-transformer-sharp": "^2.5.2",
"gatsby": "^2.22.0",
"gsap": "^3.2.6",
"husky": "^4.2.5",
"jest": "^26.0.1",
"lazysizes": "^5.2.0",
"prismjs": "^1.20.0",
"prop-types": "^15.7.2",
"react-disqus-comments": "^1.4.0",
"react-dom": "^16.12.0",
"react-helmet": "^6.0.0",
"react-instantsearch-dom": "^6.5.0",
"react": "^16.12.0",
"styled-components": "^5.1.0",
"styled-media-query": "^2.1.2"
},
"devDependencies": {
"prettier": "2.0.5"
},
} I want to use the featuredImage with gatsby-image inside the post list and the full post, but the I will use the Netlify CMS, but not now. My code is here https://github.com/dulcetti/blog and the pre-production preview is here https://brunodulcetti.netlify.app/ Does somebody help? Ah, I forgot, the branch of my tests is Regards. |
Well, I solved the case, forgot my previous comment ;) |
@dulcetti ,how did you do it?
I use gatsby develop, then it executes an error for each entry but the project works, the bad thing that gatsby build doesn't gatsby build
it's frustrating, cheers!! |
@XabierL Hi. Well, my problem is because I don't know so much the graphql, so, when the post without a filled featured image, with an empty string, show an error. Some me files have this My query on graphql(`
{
allMarkdownRemark(sort: { order: DESC, fields: frontmatter___date }) {
edges {
node {
fields {
slug
}
frontmatter {
category
date(locale: "pt-br", formatString: "DD[/]MM[/]YYYY")
title
}
timeToRead
}
}
}
}
` Before, I put the export const postQuery = graphql`
query Post($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
fields {
slug
}
frontmatter {
category
date(locale: "pt-br", formatString: "DD[/]MM[/]YYYY")
description
featuredImage {
childImageSharp {
fluid(maxHeight: 622, maxWidth: 960) {
...GatsbyImageSharpFluid
}
}
}
title
}
timeToRead
html
}
}
`; Well, I don't use the Contentful, I will use the Netlify CMS. One detail, I put the following code on the const { fmImagesToRelative } = require(`gatsby-remark-relative-images`); // <== this line
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
fmImagesToRelative(node); // <== this line
if (node.internal.type === `MarkdownRemark`) {
const slug = createFilePath({
node,
getNode,
basePath: `pages`,
});
createNodeField({
name: `slug`,
node,
value: `/${slug.slice(12)}`,
});
}
}; Off Course, my Regards |
I solved this issue by ensuring all GraphQL query name is unique. I was having two exactly same query in different files and I was getting this (Issue description) error
I renamed second query for e.g. to
And the issue is solved for me. |
Description
This morning I navigated to a Gatsby project of mine which has been in production for a year, fully functional. I launch a
gatsby develop
command and I'm getting anUnknown fragment "GatsbyImageSharpFluid_noBase64"
error even though it worked for months and I haven't changed anything...I've tried reinstalling all my dependencies, double checked everything, searched for help online but this issue really puzzles me as, and I can't stress this enough, nothing has changed since the last time it worked as expected.
I've checked the changelogs of the related packages (which I haven't updated, but I checked anyway) but no mentions as to why this would happen. Nobody seems to be experiencing the issue (or I couldn't find reports like mine).
What I've tried:
node_modules
,yarn.lock
&.cache
files & directories, reinstalled everything normally (ieyarn install
)GatsbyImageSharpFluid_noBase64
from the query below, which allows me to build the site just fine but, as you'd expect, I'm relying on this fragment so it's far from idealWhat's really strange:
I appreciate the fact that this report is somewhat strange, but I'm here looking for guidance or ideas as to why this could possibly happen and I'll investigate. Hopefully I'm just missing something super obvious someone will pick up.
The failing query
The above custom fragment is the one reported to fail, however I use the
GatsbyImageSharpFluid_noBase64
fragment elsewhere and that doesn't seem to cause an issue.The images I apply this fragment on come from Prismic.io using the
gatsby-source-prismic
plugin.Current workaround
I can build and use the site as expected if I drop the dependency to the incriminated fragment (
GatsbyImageSharpFluid_noBase64
) and replacing it withGatsbyImageSharpFluid_tracedSVG
. I've tried usingGatsbyImageSharpFluid
too, but I'm getting the same error "unknown fragment".Environment
The text was updated successfully, but these errors were encountered: