-
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
Cannot read property 'childImageSharp' of null #2567
Comments
I've had this error and for me, the path for the image was the issue. Do get the same result if you change the path for an image from |
@adamwiggall I tried that but I get the same errors |
@cryptoverted then I'm all out of ideas. I did have times where I had to restart the development server for a revised path to 'catch'. |
@adamwiggall I've tried that too |
@cryptoverted have you tried one of example sites that use gatsby-transformer-sharp? image-processing + using-gatsby-image are great examples of how to do things. |
@cryptoverted Did you try deleting the .cache and public folder and then running the dev server again? |
I'm having the same issues using the YAML transformer plugin, too. |
@KyleAMathews I've looked at that example but I mostly followed gatsbygram |
Deleting the cache rarely helps. Try installing and running an example site to see if they work for you? Perhaps it's something wrong on your OS. |
Just to shed some light on my angle with the problem, it seemed to occur most when I was referencing images in a yaml (or toml) file that were not at the root node. An example might help clarify: Works Fineimage: "./hero-bg.jpg" When I reference a file in the same directory as my yaml/toml file, the paths appear to be queryable as ImageSharp objects through both GraphiQL and Gatsby. However, if I simply nest the path reference like this: Gives the same error mentioned in the threadimage:
src: "./hero-bg.jpg" I hope this helps clarify what might be going on! |
@theutz have you tried upgrading? This is a bug that was fixed fairly recently. |
@KyleAMathews I hadn't, but I just upgraded everything and still got the bug. For reference, I'm running the following: The Packages
The Query{
allHomeYaml {
edges {
node {
title
splash {
src {
id
}
}
}
}
}
} The YAMLtitle: Everyone has the ability to recover from addiction and mental health issues
body: ....
splash:
src: ./hero-bg.jpg The Output from GraphiQL{
"errors": [
{
"message": "Path must be a string. Received undefined",
"locations": [
{
"line": 7,
"column": 11
}
],
"path": [
"allHomeYaml",
"edges",
0,
"node",
"splash",
"src"
]
}
],
"data": {
"allHomeYaml": {
"edges": [
{
"node": {
"title": "Everyone has the ability to recover from addiction and mental health issues",
"splash": {
"src": null
}
}
}
]
}
}
} |
Hmmm sounds like a bug then. Would love it if you wanted to try narrowing down the source. Failing that, the most helpful thing to do is build a reproduction site to let me or another maintainer debug what's wrong. |
@KyleAMathews We do our dev on BitBucket, but I pushed the branch we're having this problem on to a new Github repo for your perusal. Thanks! |
So tried running it locally and… it worked fine on my machine :-) Pretty site btw! |
Thanks! And thanks for looking! I'll keep trying to figure out what's going on over here! :) |
I tested both skywood and image-processing on my computer and they both work. At this point I think I am making a mistake somewhere? |
@cryptoverted thanks for the repo!! That helped me figure out what was going on. We'd been fixing this for markdown frontmatter but your reproduction helped me realize we should just do this for all nodes. PR @ #2654 |
@KyleAMathews Thanks! All working now |
Thanks to you solved my problem. |
Just a note for future readers: I had this problem after renaming a directory of a blog post. Running |
A note for everyone coming to this thread by googling. After {
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
}, After you start implementing blog posts like in the tutorial, you might add or change the code following: {
resolve: `gatsby-source-filesystem`,
options: {
name: `src`,
path: `${__dirname}/src/`,
},
}, Now, you might have something like this: const data = useStaticQuery(graphql`
query {
headerImage: file(relativePath: { eq: "header.jpg" }) { // <--- here
childImageSharp {
fluid(maxWidth: 1200) {
...GatsbyImageSharpFluid
}
}
}
}
`) Then you have error |
For some reason, when you do the first You can do a double gatsby build and it will works fine. |
Double build worked for me as well... |
Thanks so much for this! After trying pretty much everything I could find on the internet, only this worked like magic. But, why does this solve the issue? |
This fixed the issue for me, many thanks! |
I had this issue and tried the methods mentioned above, to no avail. What ended up working mysteriously was just renaming the directory containing the img coming up as null (and updating all references), and that fixed the error. |
i tried everything mentioned above. Nothing works for me. Please help. |
@DhiraNegi ... I've started getting this issue again on a new site using a pre-built theme. The solution was to stop the dev server, delete the The issue happens when you update assets queried through GraphQL while the server is running. |
In my case, I'm working with an MDX blog and what solved it was to specify the image on the MDX file. And don't forget to have an image on every folder. Before:title: Third Post!
|
I found out that I got this error because I missed the img Alt information in the .MD file I have |
I've been playing with Gatsby trying to create a website that pulls data from a json file and generates pages. On each page a list of links/cards is displayed. Everything worked fine until I added images and tried using the sharp plugin (gatsby-plugin-sharp and gatsby-transformer-sharp)
If I remove from the card.js file, image from the Card_details fragment,
const { small } = image.childImageSharp
, and the img tag, it all works as expected except no image.This error in GraphiQL
and this in the chrome console
Am I missing something or doing something wrong? The index page generates correctly and displays a list of pages, when I click to one of the pages, that is when it doesn't work. Thanks for any help.
Here is the code I use.
links.json
page.js template
card.js component
The text was updated successfully, but these errors were encountered: