-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
gatsby-transformer-json
incompatible with gatsby-source-contentful
#8538
Comments
I'm able to get around this for my particular situation with this diff, but I don't know the broader implications of relying on the availability of diff --git a/packages/gatsby-transformer-json/src/gatsby-node.js b/packages/gatsby-transformer-json/src/gatsby-node.js
index d7d55243d..fe369a6c0 100644
--- a/packages/gatsby-transformer-json/src/gatsby-node.js
+++ b/packages/gatsby-transformer-json/src/gatsby-node.js
@@ -38,7 +38,10 @@ async function onCreateNode({ node, actions, loadNodeContent, createNodeId }, pl
const { createNode, createParentChildLink } = actions
// We only care about JSON content.
- if (node.internal.mediaType !== `application/json`) {
+ if (
+ node.internal.mediaType !== `application/json` ||
+ node.internal.contentDigest
+ ) {
return
}
|
Seems like error comes from here
It expects that json comes from file ( node.dir would be there if it was). I would think that adding yet another else if (yay, more custom logic) before
with something like else if (node.internal.type !== `File`) {
return `${node.internal.type} Json`
} would potentially fix this |
this is caused by edit: we could also just use |
Thanks @pieh, @eLod. If I understand @pieh's proposal, this would still have gatsby/packages/gatsby-transformer-json/src/gatsby-node.js Lines 41 to 43 in 4173eb0
|
This would also short circuit all other non-file usage of json transformer and make it unusable for those. We need to make a change anyway to fix build breakage, so I would vote for making it work with non-file jsons. Can you access your json data when short circuiting it? |
i am not familiar with contentful, but i see it creates nodes with |
That's weird way of doing that on contentful plugin side then - if it does handle json, then it probably shouldn't create node with It seems like contentful is only plugin in this repo that is creating nodes with that mime, but I don't know about 3rd party plugins - I still think we should fix type name generation to handle non-files sources, to be sure we don't break any other existing plugins and avoid referencing other plugins if possible (checking if node was created by contentful plugin) |
@pieh Okay, README of transformer-json suggests it only works with files. We should update that to make broader usage clear. Yes, I can access my JSON data in @eLod I thought so too, but if you look the next line does
|
@pieh right, agreed, what i've meant is in addition to fixing the obvious bug with @coreyward well that is for |
@eLod Oh, gotcha. It's turtles all the way down. 😅 Pull request coming with the |
@coreyward right but that does not solve the double parsing problem. i guess contentful shouldn't parse the json itself it that's viable and rely on transformer-json as it does with markdown content i guess. |
@eLod Yep, not trying to fix two issues in one PR. In any case I think the three of us would need additional context for the rationale behind the Contentful behavior and I'm hoping to get this PR in ASAP so I can use it without referencing a fork in my dependencies. |
@coreyward you can also set the edit: e.g. see https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-json#configuration-options |
Description
I believe there's an incompatibility between
gatsby-transformer-json
andgatsby-source-contentful
that results in an error on boot. I am experiencing this issue identically to #5680 (closed, marked stale).In short,
gatsby-transformer-json/gatsby-node.js
attempts to process JSON coming back fromgatsby-source-contentful
and fails when it's unable to determine the directory that the JSON is in.Steps to reproduce
yarn
) and run developyarn add gatsby-transformer-json
gatsby-transformer-json
togatsby-config.js
Expected result
The app behaves identically.
Actual result
(note: stacks truncated)
Environment
System:
OS: macOS High Sierra 10.13.6
Binaries:
Node: 10.9.0 - /usr/local/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.2.0 - /usr/local/bin/npm
npmPackages:
gatsby: ^2.0.0 => 2.0.8
gatsby-image: ^2.0.5 => 2.0.9
gatsby-plugin-google-analytics: ^2.0.5 => 2.0.6
gatsby-plugin-offline: ^2.0.5 => 2.0.5
gatsby-plugin-typography: ^2.2.0 => 2.2.0
gatsby-source-contentful: ^2.0.1 => 2.0.1
gatsby-transformer-json: ^2.1.1 => 2.1.1
gatsby-transformer-remark: ^2.1.1 => 2.1.3
The text was updated successfully, but these errors were encountered: