Skip to content
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

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 this issue Apr 20, 2023 · 36 comments
Labels
bug Something isn't working

Comments

@rickylabs
Copy link

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"

@rickylabs rickylabs added the bug Something isn't working label Apr 20, 2023
@hpannecoucke
Copy link

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

@mykoshka
Copy link

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
Copy link

Jahorse commented Apr 23, 2023

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
Copy link

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
Copy link
Contributor

xSyki commented Apr 27, 2023

@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
Copy link

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

@laurenskling
Copy link
Contributor

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.

jinoov added a commit to jinoov/my-company that referenced this issue May 7, 2023
- conflict between gatsby-source-strapi and gatsby-source-filesystem
- @see gatsby-uc/plugins#426
@NiklasvG
Copy link

NiklasvG commented May 9, 2023

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
Copy link

soichiro0210 commented May 10, 2023

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
Copy link

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
Copy link

Is there anyone here who has fixed this problem?

@wmaasi
Copy link

wmaasi commented May 18, 2023

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
Copy link

wmaasi commented May 18, 2023

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
Copy link

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

@tinque tinque mentioned this issue May 23, 2023
@tinque
Copy link

tinque commented May 23, 2023

@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
Copy link
Contributor

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!

@tinque
Copy link

tinque commented May 25, 2023

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
Copy link
Contributor

LekoArts commented May 25, 2023

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
Copy link

tinque commented May 25, 2023

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
Copy link

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
Copy link

tinque commented May 26, 2023

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

@chcaty
Copy link

chcaty commented May 26, 2023

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

image

@tordans
Copy link

tordans commented May 26, 2023

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 gatsbyjs/gatsby#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
Copy link

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

Yeah I used the gatsby clean and keep getting the error

@sirajea
Copy link

sirajea commented May 26, 2023

@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
Copy link

solvticians-be commented May 27, 2023

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
Copy link

has anyone tried @solvticians-be 's answer?

@sirajea
Copy link

sirajea commented May 27, 2023

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

@mannp
Copy link

mannp commented May 27, 2023

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

@moonmeister
Copy link
Contributor

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. 😄

@mannp
Copy link

mannp commented May 27, 2023

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
Copy link

JunekCZ commented May 29, 2023

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

@lkarpinski
Copy link

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
Copy link

kitfoxxo commented May 31, 2023

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
Copy link

Rolling back to gatsby ~5.8.0 fixes it for me.

@LekoArts
Copy link
Contributor

Please give gatsby@5.11.0 a try, see gatsbyjs/gatsby#38117 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.