-
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
StaticImage fails extraction when imports don't match file name casing exactly #37622
Comments
Changing the header component to look like this:
Shows that the image can be shown with the |
Note that with the above change, which was pushed to the repository to recreate this problem, there should now be 3 images displayed when in reality only two are displayed |
When I tried running provided reproduction I did get an error related to file casing - I'm on linux so it's case sensitive filesystem - I did have to change https://github.com/K20shores/gatsby-mwe/blob/df7f50ac03361280efd95ad1479e53385157d829/src/components/Layout/index.js#L2 to import from Can you try making similar change and let me know if that fixes it for you? If it does, then I think we should rename to issue description from "two directories up" to file name mismatches (just to narrow things down more to what exactly the issue is) |
I tried on Windows machine with case insenstive filesystem and could reproduce the problem. Making the change I mentioned in previous comment does solve the problem, so it in fact seems related to file name / path casing |
I digged a little and here are initial findings: I think this was regression that was introduced in #37087. There was already one regression fixed for that in #37262 but that one only cared about slashes. Current behaviour I see:
this calculates to
this however results in So there is casing difference in both which cause things not to resolve properly and results in I will try to dig more and figure out how and where to fix that |
@pieh Thanks for looking into this. It seems you have already verified the issue, but I will try to verify the same thing as well and report back. I'm not familiar with the internals of gatsby, but, if I can figure out what needs to be changed based on your comments above, I'll submit a PR. |
We looked a bit more into this and decided that it's not something we can fix. The error here was that on a case insensitive filesystem your typo/error works, but not on a case sensitive one. We e.g. can't just lowercase the whole path as then otherwise a So you'll need to correct your typo and moving forward make sure that you use the correct file casing. I'd highly recommend using lowercase/kebab-case, then you won't run into that problem. |
Preliminary Checks
Description
The
StaticImage
src
attribute can only handle up to two directory redirections. For example../../images/icon.png
will show an image, but../../../images/icon.png
will not show an image and gatsby will report that the image cannot be found.Reproduction Link
https://github.com/K20shores/gatsby-mwe
Steps to Reproduce
Create a new site
npm init gatsby
. I named this onemwe
.Then install the image plugins
npm install gatsby-plugin-image gatsby-plugin-sharp gatsby-source-filesystem gatsby-transformer-sharp
.Change
gatsby-config.js
to look like this.Inside of
src
, Create this directory structure.components/index.js
components/Layout/index.js
components/Layout/layout.js
components/Layout/Header/index.js
componenets/Layout/Header/header.js
change pages/index.js to look like this
Expected Result
Two images will be displayed.
Actual Result
You will only see one image displayed. That image will be the one from
src/componenets/Layout
. The one fromsrc/componenets/Layout/Header
cannot be found.This is the output from the gatsby log.
warn [gatsby-plugin-image] Could not read image data file "/Users/kyle/Downloads/mwe/.cache/caches/gatsby-plugin-image/1281827495.json".
This may mean that the images in "/Users/kyle/Downloads/mwe/src/components/Layout/header/header.js" were not processed.
Please ensure that your gatsby version is at least 2.24.78.
warn [gatsby-plugin-image] No data found for image "../../../images/icon.png"
Environment
Config Flags
No response
The text was updated successfully, but these errors were encountered: