gatsby-uc / plugins

Monorepo for plugins in the Gatsby User Collective.
https://gatsbyuc.dev
MIT License
58 stars 34 forks source link

bug(gatsby-source-strapi): The plugin "gatsby-source-strapi" created a node of a type "File" owned by "gatsby-source-filesystem". #426

Open rickylabs opened 1 year ago

rickylabs commented 1 year ago

ERROR during gatsby develop after upgrade to Gatsby 5.9.0 & gatsby-source-filesystem 5.9.0 (with gatsby-source-strapi 3.2.0)

Log:

ERROR #11321 API.NODE.EXECUTION

"gatsby-source-strapi" threw an error while running the sourceNodes lifecycle:

The plugin "gatsby-source-strapi" created a node of a type owned by another plugin.

The node type "File" is owned by "gatsby-source-filesystem".

To Reproduce

Steps to reproduce the behavior:

  1. yarn update with below config
  2. gatsby develop

Expected behavior

Gatsby develop should not fail

System Info

"gatsby": "^5.9.0", "gatsby-source-filesystem": "^5.9.0", "gatsby-source-strapi": "^3.2.0",

"react": "^18.2.0", "node": "18.13.0"

hpannecoucke commented 1 year ago

Same here. Same version of gatsby and package. same result. Works on gatsby 5.7.0

mykoshka commented 1 year ago

Not sure if this will help, but I seem to only be having issues with images retrieved from Strapi. Everything seems to be working properly for me.

Jahorse commented 1 year ago

I also got this error trying to upgrade to the mentioned packages and versions. It seems that rolling back just the Gatsby package fixed the original error, although it did end up failing due to a different one. The new error seems unrelated... Maybe due to having newer plugin packages that are incompatible with the older gatsby? This at least seems to indicate that the original issue is with a change in the 5.9.0 gatsby package.

Before upgrading:

    "gatsby": "^5.8.1",
    "gatsby-plugin-apollo": "^4.0.3",
    "gatsby-plugin-gatsby-cloud": "^5.8.0",
    "gatsby-plugin-image": "^3.8.0",
    "gatsby-plugin-postcss": "^6.8.0",
    "gatsby-plugin-sharp": "^5.8.1",
    "gatsby-source-filesystem": "^5.8.0",
    "gatsby-source-strapi": "^3.1.3",
    "gatsby-transformer-remark": "^6.8.0",
    "gatsby-transformer-sharp": "^5.8.0",

After upgrading:

    "gatsby": "^5.9.0",
    "gatsby-plugin-apollo": "^4.0.3",
    "gatsby-plugin-gatsby-cloud": "^5.9.0",
    "gatsby-plugin-image": "^3.9.0",
    "gatsby-plugin-postcss": "^6.9.0",
    "gatsby-plugin-sharp": "^5.9.0",
    "gatsby-source-filesystem": "^5.9.0",
    "gatsby-source-strapi": "^3.2.0",
    "gatsby-transformer-remark": "^6.9.0",
    "gatsby-transformer-sharp": "^5.9.0",

At this point I got the exception about gatsby-source-strapi trying to create a File node, so I rolled back to "gatsby": "^5.8.1",, leaving all the plugins on the newest versions. After that, I got the following:

  TypeError: The 'compilation' argument must be an instance of Compilation                                                                                                           

  - NormalModule.js:228 Function.getCompilationHooks                                                                                                                                 
  - WebpackAssetsManifest.js:784 WebpackAssetsManifest.handleCompilation
    [frontend]/[webpack-assets-manifest]/src/WebpackAssetsManifest.js:784:18
  - Hook.js:14 Hook.CALL_DELEGATE [as _call]
    [frontend]/[tapable]/lib/Hook.js:14:14                                                 
  - Compiler.js:1122 Compiler.newCompilation                                                                                                                                         
    [frontend]/[gatsby]/[webpack]/lib/Compiler.js:1122:26
  - Compiler.js:1166 
    [frontend]/[gatsby]/[webpack]/lib/Compiler.js:1166:29
  - Hook.js:18 Hook.CALL_ASYNC_DELEGATE [as _callAsync]
    [frontend]/[tapable]/lib/Hook.js:18:14
  - Compiler.js:1161 Compiler.compile
    [frontend]/[gatsby]/[webpack]/lib/Compiler.js:1161:28
  - Compiler.js:524 
    [frontend]/[gatsby]/[webpack]/lib/Compiler.js:524:12
  - Compiler.js:986 Compiler.readRecords
    [frontend]/[gatsby]/[webpack]/lib/Compiler.js:986:5
  - Compiler.js:521 
    [frontend]/[gatsby]/[webpack]/lib/Compiler.js:521:11
  - Hook.js:18 Hook.CALL_ASYNC_DELEGATE [as _callAsync]                                                                                                                              
    [frontend]/[tapable]/lib/Hook.js:18:14
  - Compiler.js:518 
    [frontend]/[gatsby]/[webpack]/lib/Compiler.js:518:20
fl4viooliveira commented 1 year ago

Same problem here. In my Strapi collection, I have a "main_image" and "carousel_images" it I call bouth at the same time the error happens:

gatsby-config.ts


  collectionTypes: [
    {
      singularName: "job",
      queryParams: {
        populate: {
          title: "*",
          job_categories: "*",
          main_image: "*",
          // carousel_images: "*", ---> if take of the comment the code broke.
        },
      },
    },
  ],
xSyki commented 1 year ago

@laurenskling The error is obviously related to: https://www.gatsbyjs.com/docs/reference/release-notes/v5.9/#performance-improvements. It's strange that such breaking changes appear in the minor version. Currently, gatsby-source-strapi doesn't even mention that it doesn't support gatsby 5.9.0, I think this should have a very high priority.

ramit-mitra commented 1 year ago

Started getting this same error with Gatsby v5 & Strapi v3.6.9.

laurenskling commented 1 year ago

File is used for images yes, so images would be the trigger. @xSyki , enableStatefulSourceNodes seems to be opt-in. If we are not using it, nothing should break I guess? It's kind of hard to mention that you don't support a version before it is released, right? ;)

@ramit-mitra Strapi 3 isn't supported by the latest version of this package. You can only use v1.

I am currently still on Gatsby 4, so I cannot really help directly with this error. Plus I have no free time to look into it currently. I invite everyone here to contribute into getting this error solved.

NiklasvG commented 1 year ago

I got the same error with gatbsy 5.8.1. I tried to use gatsby 5.7.0 but still getting the error.

Is there a good package combination where it works at the moment?

soichiro0210 commented 1 year ago

In my case, the build problem solved by adding remoteFileHeaders to strapiConfig in the gatsby-config.

Like this

remoteFileHeaders: {
    Referer: "https://xxxxx.com/",
    Authorization: "Bearer " + process.env.STRAPI_TOKEN,
  },
rileybathurst commented 1 year ago

I renamed a bunch of the variables in /gatsby-source-strapi/dist/download-media-files.js to https://gist.github.com/rileybathurst/81ccfc5ef46e9c2b93f3105ffee3b58b

I don't know which one is the fix but something in here lets the site build. renaming in the src file would be way more useful but this is going to require testing to know what I'm actually adjust and make sure I am not breaking things

MuhammadSalmanSiddiqui commented 1 year ago

Is there anyone here who has fixed this problem?

wmaasi commented 1 year ago

Hello,

I have the same trouble

Error: The plugin "gatsby-source-strapi" 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). The plugin creating the node:

wmaasi commented 1 year ago

I renamed a bunch of the variables in /gatsby-source-strapi/dist/download-media-files.js to https://gist.github.com/rileybathurst/81ccfc5ef46e9c2b93f3105ffee3b58b

I don't know which one is the fix but something in here lets the site build. renaming in the src file would be way more useful but this is going to require testing to know what I'm actually adjust and make sure I am not breaking things

UPDATE:

Thanks a lot @rileybathurst

Now it works, but also you have to change the line 57 in /gatsby-source-strapi/dist/gatsby-node.js to

const existingNodes = getNodes().filter(n => n.internal.owner === `gatsby-source-strapi` || n.internal.type === "strapiFile");

Regards

carlo711 commented 1 year ago

downgrading to gatsby 5.7.0 and gatsby-source-filesystem 5.8.0 worked for me.

tinque commented 1 year ago

@laurenskling I attempted the suggested approach (enableStatefulSourceNodes) but unfortunately did not achieve the desired outcome.

Considering the issue stems from the node ownership override by the gatsby-source-filesystem plugin, it appears that the current fix is not ideal. In order to address this problem, I should propose an option within the createRemoteFileNodemethod from the gatsby-source-filesystem plugin that allows users to prevent the override of ownership when it used with another plugin. This approach would provide a more flexible and customizable solution.

LekoArts commented 1 year ago

Gatsby maintainer here 👋

Can you please open a bug report in our repo about this: https://github.com/gatsbyjs/gatsby/issues/new?assignees=&labels=type%3A+bug&projects=&template=BUG_REPORT.yml

This shouldn't happen and is probably a regression from https://github.com/gatsbyjs/gatsby/pull/37782 The current PR https://github.com/gatsby-uc/plugins/pull/431 shouldn't be merged as this needs to be fixed inside gatsby

Thanks!

tinque commented 1 year ago

Gatsby maintainer here 👋

Can you please open a bug report in our repo about this: https://github.com/gatsbyjs/gatsby/issues/new?assignees=&labels=type%3A+bug&projects=&template=BUG_REPORT.yml

This shouldn't happen and is probably a regression from gatsbyjs/gatsby#37782 The current PR #431 shouldn't be merged as this needs to be fixed inside gatsby

Thanks!

Hello @LekoArts, I don't understand why it's considered a regression in gatsby ?! This current plugin is managing nodes without ownership of them. I believe that's a bad practice, isn't it?

LekoArts commented 1 year ago

In simple terms:

File nodes should be managed by gatsby-source-filesystem and that's how it used to work in the past.

However, https://github.com/gatsby-uc/plugins/pull/431/files#diff-77a5459c74cf8818897d5690b621b8bca7f96d363a1eb68a6ed55f65711e061aR61 seems like a correct change. The source plugin shouldn't touch File nodes, it should only touch its own nodes: https://www.gatsbyjs.com/docs/tutorial/creating-a-source-plugin/part-5/#1-prevent-garbage-collection

So does your PR fix it if you remove the createNode change?

tinque commented 1 year ago

Hello,

Thanks for the explanation !

Nope, it doesn't work if you don't have the gatsby-source-filesystem plugin configured in your Gatsby config. I tried installing and configuring it, but it still doesn't work because the plugin doesn't manage this node... it's a vicious circle.

For me the gatsby-source-filesystem shouldn't override the createNode function => https://github.com/gatsbyjs/gatsby/blob/ccbbda5c6ae4cc9dfcbbf07891e9c74461c6ed55/packages/gatsby-source-filesystem/src/create-remote-file-node.js#L70

But I don't have the energy to open an issue and deep dive into the issue for the gatsby-source-filesystem. I need this plugin to work quickly because it's currently causing an issue for me in production.

rileybathurst commented 1 year ago

Hey @tinque are you doing anything other than the https://github.com/tinque/gastby-uc-plugins/commit/1a174f827be2b3810b9f7b2be27f0f85fd505560 updates? I am still hitting the issue with those updates

I get a console error showing

err Error: The plugin "gatsby-source-strapi-file" 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).

  The node object passed to "createNode":

          {
"id": "07830568-75f4-5d49-adf8-34461fe2d611",
"children": [],
"parent": null,
"internal": {
    "contentDigest": "2cfc1069b5169da43528a756686748c2",
    "type": "File",
    "mediaType": "image/webp",
    "description": "File \"http://45.79.101.19:1340/uploads/TWIG_Member_Seal_2022_23_41c176880a.webp\"",
    "owner": "gatsby-source-strapi-file",
    "counter": 76
},
"sourceInstanceName": "__PROGRAMMATIC__",
"relativePath":

".cache/caches/gatsby-source-strapi-file/0fe16aae7ec04193134414747f7d0c86/TWIG_Member_Seal_2022_23_41c176880a.webp", "extension": "webp", "prettySize": "14 kB", "modifiedTime": "2023-05-26T03:51:00.279Z", "accessTime": "2023-05-26T03:51:00.181Z",

tinque commented 1 year ago

Hey @rileybathurst 🙂 Did you remove your .cache folder after applying the patch?

chcaty commented 1 year ago

Hey @tinque I have executed the command gatsby clean and deleted the Cache folder, but I still get the same error message .

image

tordans commented 1 year ago

Gatsby maintainer here 👋 Can you please open a bug report in our repo about this: https://github.com/gatsbyjs/gatsby/issues/new?assignees=&labels=type%3A+bug&projects=&template=BUG_REPORT.yml

I went ahead and created an issue at https://github.com/gatsbyjs/gatsby/issues/38117 to track this topic upstream in Gatsby.

@LekoArts please update the title so something that makes sense for the Gatsby Repo. Let me know it the ticket over there needs more information that is not present in this thread.

rileybathurst commented 1 year ago

Hey @rileybathurst 🙂 Did you remove your .cache folder after applying the patch?

Yeah I used the gatsby clean and keep getting the error

sirajea commented 1 year ago

@tinque I confirm that the proposed PR doesn't work, using: gatsby 5.8.1, gatsby-source-strapi 3.2.0. Still getting the same error message "The node type "File" is owned by "gatsby-source-filesystem"", even after running gatsby clean.

solvticians-be commented 1 year ago

In node_modules/gatsby-source-strapi/dist/gatsby-node.js, if you remove the internal type check of "File" in the below line (line 57): const existingNodes = getNodes().filter(n => n.internal.owner ===gatsby-source-strapi|| n.internal.type === "File");

And then remove the touchNode on line 78 of download-media-files.js and return the fileNodeID when cached (see below taken from lines 76-80), then both pieces will work.

if (cacheMediaData && cacheMediaData.updatedAt === file.updatedAt) {
    fileNodeID = cacheMediaData.fileNodeID;
    //touchNode(getNode(fileNodeID));
    return fileNodeID;
  }
orkunzozturk commented 1 year ago

has anyone tried @solvticians-be 's answer?

sirajea commented 1 year ago

@orkunzozturk I confirm that @solvticians-be 's change appears to be working.

mannp commented 1 year ago

Not trying to hijack the thread, but I have noted this same issue with the Directus source plugin for gatsby.

The same error and issue, while reverting to gatsby 5.8 and gatsby-source-filesystem 5.8 things work again.

https://github.com/directus/gatsby-source-directus/issues/25

moonmeister commented 1 year ago

Not trying to hijack the thread, but I have noted this same issue with the Directus source plugin for gatsby.

The same error and issue, while reverting to gatsby 5.8 and gatsby-source-filesystem 5.8 things work again.

https://github.com/directus/gatsby-source-directus/issues/25

Hence @LekoArts is saying they need to fix a bug in Gatsby. 😄

mannp commented 1 year ago

Not trying to hijack the thread, but I have noted this same issue with the Directus source plugin for gatsby. The same error and issue, while reverting to gatsby 5.8 and gatsby-source-filesystem 5.8 things work again. directus/gatsby-source-directus#25

Hence @LekoArts is saying they need to fix a bug in Gatsby. smile

Indeed, merely adding further context to the issue.

JunekCZ commented 1 year ago

I fixed it by moving resolve 'gatsby-source-strapi' above the gatsby-source-filesystem and then ran the gatsby clean command.

lkarpinski commented 1 year ago

I fixed it by moving resolve 'gatsby-source-strapi' above the gatsby-source-filesystem and then ran the gatsby clean command.

can you send a screenshot with package.json?

kitfoxxo commented 1 year ago

Also having this issue, moved gatsby-source-strapi to top of plugins, ran gatsby clean multiple times, and manually deleted the .cache directory, still no dice. Attached are screenshots of my package.json and gatsby-config.ts.

Screenshot from 2023-05-31 13-29-36 Screenshot from 2023-05-31 13-30-01

kitfoxxo commented 1 year ago

Rolling back to gatsby ~5.8.0 fixes it for me.

LekoArts commented 1 year ago

Please give gatsby@5.11.0 a try, see https://github.com/gatsbyjs/gatsby/issues/38117#issuecomment-1592719231