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

gatsby-source-contentful build fails if "localized" isn't present on content model #38445

Open
2 tasks done
Dman757 opened this issue Aug 9, 2023 · 0 comments
Open
2 tasks done
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby

Comments

@Dman757
Copy link

Dman757 commented Aug 9, 2023

Preliminary Checks

Description

Ran into an issue today when building a fresh project with an older (migrated) contentful space.

I believe the issue was that the localized key wasn't attached to the content model response. Resolved the issue after a lot of digging by using the contentful CLI to set localized manually. Followed this guide from contentful

I can't provide a reproduction but I can provide you with the specific error and what I believe is the line in question causing the problem. Based on the error output being in noramize.js I did a quick search for localized in the gatsby-source-contentful codebase and found the specific line that would (probably break) if it was undefined. My suggestion is add optional chaining. to fieldProps?.localized

        const localizedField = fieldProps.localized
          ? getField(v)
          : v[defaultLocale]

Source: https://github.com/gatsbyjs/gatsby/blob/fd8de341684df7aa5fcd911a25786beac471925c/packages/gatsby-source-contentful/src/normalize.js#L507C52-L507C52

 ERROR #11321  API.NODE.EXECUTION

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

Cannot read properties of undefined (reading 'localized')



  TypeError: Cannot read properties of undefined (reading 'localized')
  
  - normalize.js:467 
    [thekin-website]/[gatsby-source-contentful]/normalize.js:467:43
  
  - mapValues.js:38 
    [thekin-website]/[lodash]/mapValues.js:38:34
  
  - _createBaseFor.js:17 
    [thekin-website]/[lodash]/_createBaseFor.js:17:11
  
  - _baseForOwn.js:13 baseForOwn
    [thekin-website]/[lodash]/_baseForOwn.js:13:20
  
  - mapValues.js:37 mapValues
    [thekin-website]/[lodash]/mapValues.js:37:3
  
  - normalize.js:465 
    [thekin-website]/[gatsby-source-contentful]/normalize.js:465:55
  
  - Array.map
  
  - normalize.js:455 
    [thekin-website]/[gatsby-source-contentful]/normalize.js:455:32
  
  - Array.forEach
  
  - normalize.js:431 createNodesForContentType
    [thekin-website]/[gatsby-source-contentful]/normalize.js:431:11
  
  - source-nodes.js:399 Object.sourceNodes
    [thekin-website]/[gatsby-source-contentful]/source-nodes.js:399:52
  
  - api-runner-node.js:509 runAPI
    [thekin-website]/[gatsby]/src/utils/api-runner-node.js:509:16

Reproduction Steps

Line In noramize.js that unsafely expect's a localized value to be present

I can't provide a reproduction but I can provide you with the specific error and what I believe is the line in question causing the problem.

(If you have tests of a mocked up contentful response, try deleting the localized key and see if it passess)

https://github.com/gatsbyjs/gatsby/blob/fd8de341684df7aa5fcd911a25786beac471925c/packages/gatsby-source-contentful/src/normalize.js#L507C52-L507C52

Environment

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Pro
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.16.0 - /var/folders/h6/_yw0zyy50rs475y38kynv5tm0000gn/T/yarn--1691541523545-0.03639385144958629/node
    Yarn: 1.22.19 - /var/folders/h6/_yw0zyy50rs475y38kynv5tm0000gn/T/yarn--1691541523545-0.03639385144958629/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Chrome: 113.0.5672.126
    Safari: 15.6.1
  npmPackages:
    gatsby: ^5.11.0 => 5.11.0 
    gatsby-plugin-image: ^3.11.0 => 3.11.0 
    gatsby-plugin-sass: ^6.11.0 => 6.11.0 
    gatsby-plugin-sharp: ^5.11.0 => 5.11.0 
    gatsby-source-contentful: ^8.11.0 => 8.11.0 
    gatsby-transformer-sharp: ^5.11.0 => 5.11.0

Config Flags

None

@Dman757 Dman757 added the type: bug An issue or pull request relating to a bug in Gatsby label Aug 9, 2023
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Aug 9, 2023
@Dman757 Dman757 changed the title Build fails is "localized" isn't present on content model. Build fails if "localized" isn't present on content model. Aug 9, 2023
@Dman757 Dman757 changed the title Build fails if "localized" isn't present on content model. gatsby-source-contentful build fails if "localized" isn't present on content model Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

1 participant