prismicio / prismic-gatsby

Gatsby plugins for building websites using Prismic
https://prismic.io/docs/technologies/gatsby
Apache License 2.0
313 stars 97 forks source link

Conflict between gatsby-source-prismic and gatsby-source-filesystem - Breaks Build #530

Closed LiamJSP closed 1 year ago

LiamJSP commented 1 year ago

Versions

Steps to reproduce

  1. Clone this repo: https://github.com/RedCloverSoftware/redclover-website-gatsbyjs.git
  2. yarn install
  3. yarn upgrade --latest gatsby && yarn upgrade --latest gatsby-source-prismic && yarn upgrade --latest gatsby-source-filesystem
  4. Update your global gatsby-cli if not at latest.
  5. yarn build

    What is expected?

    A successful build

    What is actually happening?

    After upgrading to the latest version of gatsby and gatsby-source-prismic, the site can no longer be built, due to a conflict between the plugin gatsby-source-prismic, and the official gatsby plugin gatsby-source-filesystem (used by gatsby-plugin-image). This is the specific error:

Error: The plugin "gatsby-source-prismic" created a node of a type owned by another plugin. The node type "File" is owned by "gatsby-source-filesystem". If you copy and pasted code from elsewhere, you'll need to pick a new type name for your new node(s).

Full build log with error

Reverting to the previous version of just gatsby-source-prismic that produced working builds for me (5.2.9) did not resolve this error, it appears that the latest version of Gatsby 5.x (specifically 5.9.0) is involved in this error, as this does not happen when using gatsby 4.21.1 and gatsby-source-prismic 5.2.9. Is gatsby-source-prismic not compatible with Gatsby 5.x at the moment? Or is this some sort of odd dependency conflict particular to my repo? I have tried a build with all top-level deps set to pull latest versions ("*"), no change. Appreciate any assistance or thoughts!

LiamJSP commented 1 year ago

I tried to setup a prismic gatsby starter following the official prismic guide just to verify whether this issue was unique to my site's repo, and the starter setup also seems to be broken at the current version ("creating prismic repository... invalid custom types format")... can someone do a sanity check for me, is Gatsby 5.x and Prismic currently completely broken? The starter attempts to use Gatsby 5.x so it seems like it should be supported?

For reference I have also created a Prismic Forum post here: https://community.prismic.io/t/gatsby-5-x-and-prismic-seems-broken/13032

angeloashmore commented 1 year ago

Hi @LiamJSP, just wanted to let you know I’m aware of the issue you reported and will take a look at it as soon as possible. I am currently working on Prismic’s Next.js integration and will be revisiting Gatsby right after.

In the meantime, I recommend using the latest version of Gatsby that works with gatsby-source-prismic. The plugin works with Gatsby 5, but it’s possible some breaking change was published in the last east version of Gatsby.

LiamJSP commented 1 year ago

@angeloashmore Thanks for the heads up! I'll continue to do some digging and add any helpful info I can find or if I'm lucky open a PR :)

LiamJSP commented 1 year ago

Small update, the prismic CLI works fine on my macbook, so not sure if it's a global dependency issue with my windows workstation. Just letting you know we can exclude it from this issue, it's just the odd conflict between gatsby-source-prismic and gatsby-source-filesystem, I have an update on this too:

After sucessfully cloning the gatsby prismic starter and upgrading it's Gatsby and all plugins to latest, there was no issue. So this suggests an issue with my repo, but I'm just not sure where to look - the two plugins were working fine prior to upgrading, and the error thrown leaves no room to imagining any other cause ("Error: The plugin "gatsby-source-prismic" created a node of a type owned by another plugin."). Any thoughts where I should be digging for this issue? My gatsby-config.js appears fine, here is the two relevant parts for both plugins:

{ resolve: gatsby-source-filesystem, options: { name: images, path: path.resolve(__dirname, 'src', 'images'), }, }, { resolve: gatsby-source-prismic, options: { repositoryName: process.env.GATSBY_PRISMIC_REPO_NAME, accessToken: process.env.PRISMIC_ACCESS_TOKEN, customTypesApiToken: process.env.PRISMIC_CUSTOM_TYPES_API_TOKEN, shouldDownloadFiles: () => true, }, },

Let me know if you're aware of anything that could cause a duplicate node type error after upgrading, only in one particular repo! I'll keep looking too

niklaspesch commented 1 year ago

I stumbled across the same issue and can say it's due to shouldDownloadFiles, if you comment that out, the dev server starts up normally. But then the problem is that I can no longer get images/files via localFile. Does this help you further @angeloashmore?

maheshsamudra commented 1 year ago

I'm having the same issue with gatsby-source-filesystem@5.10, gatsby@5.10 and gatsby-source-prismic@5.3.1 on Mac. The issue disappears with shouldDownloadFiles: false, but that's not an option for my project.

LiamJSP commented 1 year ago

Popping back in to add that I've since found that this issue affected the entire Gatsby source plugin ecosystem. Almost every source plugin that utilized a File node type was broken by Gatsby's changes in recent versions. You can find similar issues for Strapi (https://forum.strapi.io/t/is-gatsby-source-strapi-currently-broken/28147) , DirectUs (https://github.com/gatsby-uc/plugins/issues/426) etc. Despite the message in the Gatsby error, Prismic didn't copy-paste code, and from my investigation it looks like they're using a link type to tie-in to the vanilla "File" node to allow for consistency in GQL queries (refer to files as localFile).

I experimented a bit with various bandaid fixes I found in different plugin repos (moved gatsby-source-prismic above gatsby-source-filesystem in gatsby-config.js, attempted to rename the internal.type name for File within gatsby-source-prismic, etc). but didn't have any luck.

TL;DR It's a gatsby bug/possibly planned breaking change (as I see some mention of changes to node ownership in the changelog of recent versions).

LiamJSP commented 1 year ago

A member of the Gatsby team confirmed they're aware and looking into a fix!

LekoArts commented 1 year ago

Please see https://github.com/gatsbyjs/gatsby/issues/38117#issuecomment-1592719231 and give it a try :)

LiamJSP commented 1 year ago

We got a working build! I'll leave the issue open until a few other people chime in. Thanks so much for your help on this LekoArts, just pasting your advice in the other thread as it might be useful for future development here:

Best Practices When Dealing with File Nodes courtesy of LekoArts: