gatsby: Generating SSR bundle failed - Can't resolve 'gatsby-link' in 'xxx/.cache'
Description
When I try to run gatsby build
or gatsby develop
I keep running into the following issue
Generating SSR bundle failed
Can't resolve 'gatsby-link' in 'xxx/.cache'
If you're trying to use a package make sure that 'gatsby-link' is installed. If you're trying to use a local file make sure that the path is correct.
File: .cache/gatsby-browser-entry.js
Steps to reproduce
This is project that has been working for a few months and I’ve updated yesterday and now I’m getting the above error message
Expected result
Should be able to run gatsby build
and gatsby develop
with no errors
Actual result
Error mentioned above
Environment
System:
OS: macOS 10.15.3
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 14.5.0 - ~/.nvm/versions/node/v14.5.0/bin/node
Yarn: 1.22.4 - ~/.yvm/shim/yarn
npm: 6.14.5 - ~/.nvm/versions/node/v14.5.0/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 83.0.4103.116
Edge: 83.0.478.61
Firefox: 76.0
Safari: 13.0.5
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 11
- Comments: 24 (12 by maintainers)
Commits related to this issue
- add gatsby-link — committed to zandaleph/bookish-carnival by zandaleph 4 years ago
Have you tried deleting the node-modules folder and the package-lock.json file, running gatsby clean, followed by npm install or yarn? That usually does the trick for me with cache issues, frustrating when they pop up for seemingly no reason out of nowhere!
In my case this problem was caused by the way Yarn hoists dependencies if you’re using its workspaces feature.
The workspace folder structure looks something like this:
Because both
project-a
andproject-b
depend on the same version ofgatsby
, Yarn hoists it to the rootnode_modules
. Because nothing else in the workspace depends ongatsby-link
, Yarn installs that underneathgatsby
. The result looks like this:When
project-a/.cache/whatever.js
requiresgatsby-link
, the module isn’t in scope because it isn’t in the localproject-a/node_modules
and it’s not visible in the rootnode_modules
. That’s why you can resolve the issue withyarn add gatsby-link
in one or both of the projects - doing so will cause Yarn to hoist it into the top level of the rootnode_modules
alongsidegatsby
, which brings it into scope. In other words, if you can get to this situation, it’ll work:I think this could legitimately be called a Gatsby issue, because the files in the
.cache
folder are making assumptions Yarn doesn’t recognise, though I’m not sure how’d you’d go about solving it.@domjtalbot on
gatsby@2.20.36
had exactly the same issue andyarn add
inggatsby-link
andgatsby-react-router-scroll
as direct dependencies solved the issue. Not sure why this is happening, but glad to see that it’s not just me.I had this issue when upgrading to
gatsby@5.1.0
. Seemed to be resolved after removing the@gatsbyjs/reach-router
dependency. But now I broke my SEO component which was dependent on that package 😕 Anyone have an idea how to fix this without removing the package?I had this issue when updated to
gatsby@5.0.0
. The issue was that I had@gatsbyjs/reach-router
in my app’s dependencies, after removing it the build went fineHaving the same issue after upgrading to
gatsby@2.29.1
. As mentioned in https://github.com/gatsbyjs/gatsby/issues/3069, not sure whygatsby-link
isn’t just included in the gatsby package?same with the package
gatsby-react-router-scroll
.@blainekasten would it help to have particular dependency version information in the changelog? For example, “as of version gatsby 1.2.3 you will need to have to at least: gatsby-plugin-something-or-other 3.2.1 and gatsby-transformer-something-or-other 4.5.6 installed alongside it”. What do you think?