Skip to content

Cannot convert undefined or null to object - when some image nodes are null #68

Description

@amcc

The plugin is functioning and we get graphQL nodes created from the Cloudinary images, however we get the following error:

error "gatsby-transformer-cloudinary" threw an error while running the onCreateNode lifecycle:

Cannot convert undefined or null to object

  53 |   const currentNode = basePath === '' ? node : get(node, basePath);
  54 | 
> 55 |   const directAssetDataPaths = Object.keys(currentNode)
     |                                       ^
  56 |     .filter(key => {
  57 |       return currentNode[key] && currentNode[key].cloudinaryAssetData === true;
  58 |     })


  TypeError: Cannot convert undefined or null to object
  
  - Function.keys
  
  - create-asset-nodes-from-data.js:55 getAssetDataPaths
    [mysite]/[gatsby-transformer-cloudinary]/gatsby-node/create-asset-nodes-from-data.js:55:39
...

This occurs in develop and build, in develop it will get past this error, but build fails.

We are adding an object for cloudinary with all the applicable data, but due to our database structure this object is occasionally null. For instance:

mediaItems: [
   {
   ...,
   "cloudinary": {
      "cloudName": "mycloudname",
      "orginalHeight: 2250,
      "cloudinaryAssetData": true,
      ...
       }
   },
   "cloudinary": null
]

Currently the situation is that the plugin appears to be working ok - the above structure is how it looks before the plugin is working. These get replaced with the fixed/fluid image graphQL node and the plugin appears to be working fine. But it still produces the error above, which of course fails the build.

It would be good if this isn't an error! A warning at most, so long as it finds at least some useable objects that would seem to be sufficient. Unfortunately making changes to our DB is a little difficult, there may be a way round this with gatsby-node.js, but it would be good to see if there's a fix perhaps.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions