gatsby: [bug]: ☂️ umbrella issue for cache and over-eager persistence issues
Description
In this umbrella issue, I’d like to provide a means for others to share any issues encountered regarding caching, specifically in instances when the solution to a problem you were facing was remediated by removing the cache (e.g. rm -rf .cache
).
Issues that we have seen before (but generally have not been able to reproduce) can usually be classified as one of the following:
- Remote content sourced by a plugin is available (e.g. in the database, CMS, etc.) but is not available after a local re-build
- A local plugin source code changed, but the change(s) do not seem to have taken effect
- Local content (e.g. images, Markdown, etc.) were changed, but the changes do not seem to show up after a build
If any of these scenarios, or more broadly speaking, if you’ve ran into a problem where content wasn’t appearing appropriately and deleting the cache solved this problem–then please chime in!
Intent
If we can reliably reproduce these types of issues and scenarios, we can harden our cache and improve the experience for all Gatsby users. Specifically, if we can reliably reproduce we can fix the underlying issue and then author end-to-end tests to ensure that the caching issue remains fixed.
Template
Please use the following template to report an issue so that we can most effectively debug the underlying issue.
Note: it is extremely important that you provide as much information as possible for the reproduction step. The more info and clearer the reproduction, the better we will be able to debug and ship fixes to these issues!
## Description
<!-- What led you to delete the cache? What was the exact problem that deleting the cache seemed to have fixed? -->
## Reproduction
<!-- Please, please provide detailed steps to reproduce. Ideally a Github repository where we can reproduce the issue(s) ourselves, as well. -->
## Environment Info
<!-- Run `npx gatsby info --clipboard` in the root of your Gatsby app and paste the output here -->
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 38 (12 by maintainers)
Though it is undocumented it seems one can use Gatsby’s cache object to set and get json objects. Data is stored in the
.cache/cache/{plugin-name}/
directory.In your plugin
gatsby-node.js
in one of the many apis includecache
as an argument; eg.Issue: Import error when using component shadowing in gatsby-theme with gatsby 5.2.0
Description:
I am experiencing an import error when working with component shadowing in a gatsby-theme that uses gatsby 5.2.0. Every time I make a change in the codebase, I get the following error:
Attempted import error: ‘$virtual/async-requires’ does not contain a default export (imported as ‘asyncRequires’).
The only way to resolve this error is to run
gatsby clean
and thengatsby start
again.Steps to reproduce:
Expected behavior:
I expect the code to recompile and update the site without any errors.
Actual behavior:
I am getting the import error described above every time I make a change in the codebase.
Environment:
Additional context:
Has anyone else encountered this issue before? Is there a fix or workaround for this problem? I would really appreciate any help or guidance on how to resolve this issue. Thank you!
A potential cause of caching issues is mentioned here.
In short - if you create a node using
createNode
, without setting theparent
field correctly, the node can be incorrectly garbage collected as part of the bootstrap process. Clearing the cache will correctly recreate the node.This is a pretty systemic problem whenever adding a new image. Pretty much exclusively I have to
rm -rf .cache/
and re-install. Sometimes I also just nuke thepublic/
folder. I know this is sort of already known, just figured that I’d share that I have had this experience.Oops, unpinned this accidentally. Sorry!
(Perhaps GitHub should make repository actions more obvious 😛)
I have been having some issues with the cache as well, but on the other side. I have pretty bad internet for the time being, and having gatsby clear the cache every time I change a config is pretty frustrating. Rebuilds can take ~15 minutes. Wondering if we should cache different objects (images vs configs or built files) differently?
I think I ran into this issue and after much frustration I started this issue but ended up closing it after deleting the public folder and getting everything to work. I do believe this sounds a lot like what others are experiencing though.
@edsu This is likely it. gatsby-transformer-json uses your id if you supply one but Node IDs must be universally unique as all nodes live in the same namespace — see https://www.gatsbyjs.com/docs/reference/config-files/actions/#createNode
I abstracted a lot of functions utilized inside my
sourceNodes
function into a separate file. Changes made in that file were not detected by cache busting, and so any time I changed the code in my abstracted file, I would have to clear the cache manually. Any way that Gatsby could detect changes in required files withingatsby-node.js
would be advantageous to my use case.We’ve run into an issue with contentful where, when we’ve added images via a rich-text, we’ve had to delete the
.cache
folder in order to query additional properties with GraphQL on the embedded asset.For instance, we’ve added images, re-started the dev server, and were still unable to query image properties like
deleting the
.cache
folder, solved this for us.Please bear in mind that I am not 100% sure this was the cause of the issue forcing me to delete the
.cache
directory but it did fix the issue as soon as I did. I have ajson
file with an array of objects. I decided to give each object anidentifier
key. Gatsby does not like this key name, maybe it conflicts with an internal key name. I renamed theidentifier
toname
but the related changes were not being built until I deleted the.cache
directory.