datocms / gatsby-source-datocms

Official GatsbyJS source plugin to pull content from DatoCMS
MIT License
140 stars 50 forks source link

TypeError: Cannot read properties of undefined (reading 'editor') #219

Closed dante-blitz closed 1 year ago

dante-blitz commented 1 year ago

I'm getting the following error when trying to build Gatsby.

The issue is occurring both locally (Windows 10) and when attempting to deploy on Netlify (Node 18.16.0).

I started getting this on an existing project. I have since tried on a vanilla Gatsby site and the issue still occurs.


  "dependencies": {
    "gatsby": "^5.9.1",
    "gatsby-plugin-google-gtag": "^5.9.0",
    "gatsby-plugin-image": "^3.9.0",
    "gatsby-plugin-manifest": "^5.9.0",
    "gatsby-plugin-sharp": "^5.9.0",
    "gatsby-plugin-sitemap": "^6.9.0",
    "gatsby-source-datocms": "^5.1.1",
    "gatsby-source-filesystem": "^5.9.0",
    "gatsby-transformer-remark": "^6.9.0",
    "gatsby-transformer-sharp": "^5.9.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
dante-blitz commented 1 year ago

$ npm run build

> gatsby-5-test@1.0.0 build
> gatsby build

success compile gatsby files - 5.013s
success load gatsby config - 0.095s
success load plugins - 3.307s
success onPreInit - 0.020s
success initialize cache - 0.207s
success copy gatsby files - 0.758s
success Compiling Gatsby Functions - 0.712s
success onPreBootstrap - 0.762s
success loading DatoCMS schema - 5.299s
success createSchemaCustomization - 5.435s

 ERROR #11321  API.NODE.EXECUTION

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

Cannot read properties of undefined (reading 'editor')

  TypeError: Cannot read properties of undefined (reading 'editor')

  - index.js:24 
    [gatsby-5-test]/[gatsby-source-datocms]/hooks/sourceNodes/createNodeFromEntity/item/index.js:24:39

  - Array.flatMap

  - index.js:22 Object.buildItemNode [as item]
    [gatsby-5-test]/[gatsby-source-datocms]/hooks/sourceNodes/createNodeFromEntity/item/index.js:22:6

  - index.js:30 module.exports
    [gatsby-5-test]/[gatsby-source-datocms]/hooks/sourceNodes/createNodeFromEntity/index.js:30:37

  - index.js:180 
    [gatsby-5-test]/[gatsby-source-datocms]/hooks/sourceNodes/index.js:180:17

  - Array.forEach

  - index.js:179 
    [gatsby-5-test]/[gatsby-source-datocms]/hooks/sourceNodes/index.js:179:66

  - Array.forEach

  - index.js:178 _callee2$
    [gatsby-5-test]/[gatsby-source-datocms]/hooks/sourceNodes/index.js:178:55

  - regeneratorRuntime.js:44 tryCatch
    [gatsby-5-test]/[@babel]/runtime/helpers/regeneratorRuntime.js:44:17

  - regeneratorRuntime.js:125 Generator.<anonymous>
    [gatsby-5-test]/[@babel]/runtime/helpers/regeneratorRuntime.js:125:22

  - regeneratorRuntime.js:69 Generator.next
    [gatsby-5-test]/[@babel]/runtime/helpers/regeneratorRuntime.js:69:21

  - index.js:3 asyncGeneratorStep
    [gatsby-5-test]/[gatsby-source-datocms]/hooks/sourceNodes/index.js:3:103

  - index.js:5 _next
    [gatsby-5-test]/[gatsby-source-datocms]/hooks/sourceNodes/index.js:5:194

not finished source and transform nodes - 0.428s
cdennington commented 1 year ago

I'm also experiencing this issue.

It appears to be caused by the Multiple-paragraph text field. If I start a new project that doesn't use this field I do not get the error.

Ive also tried changing the editor of this field, but HTML, markup and textarea all have the same issue.

Finally I have upgraded my version of gatsby-source-datocms from 5.0.4 to 5.1.1, which is the latest version, but the issue still persists.

cdennington commented 1 year ago

Ive just spent some time debugging this, it appears to be a spelling change, I assume from Dato's side and not this package as the file which has the issue hasn't changed in a long time: https://github.com/datocms/gatsby-source-datocms/blob/master/src/hooks/sourceNodes/createNodeFromEntity/item/index.js#LL20C48-L20C48

The issue is with this line const mediaType = field.appeareance.editor === 'markdown' ? 'text/markdown' : field.appeareance.editor === 'wysiwyg' ? 'text/html' : 'text/plain';

field.appeareance does not exist and should be changed to field.appearance

I will create a pull request

stefanoverna commented 1 year ago

Fixed in v5.1.2!