Gatsby: [gatsby-source-filesystem] TypeError: Cannot read property 'internal' of null

Created on 2 Aug 2018  路  11Comments  路  Source: gatsbyjs/gatsby

This may be an unrelated issue but I am getting the error when trying fetch cache after using createRemoteFileNode from gatsby-source-filesystem.

let updated = {}

          if (res[`webImages`]) {
            const updatedImages = await Promise.all(
              res[`webImages`].map(async img => {
                let fileNodeID
                const webImageCacheKey = `web-images-${img.id}`
                // TypeError: Cannot read property 'internal' of null on 2nd run .  <--- this is were I get this error after the cache has been stored the first time.
                const cacheMediaData = await cache.get(webImageCacheKey)

                if (cacheMediaData) {
                  fileNodeID = cacheMediaData.fileNodeID
                  touchNode({ nodeId: cacheMediaData.fileNodeID })
                }

                if (!fileNodeID) {
                  try {
                    const fileNode = await createRemoteFileNode({
                      url: cloud(img.url, `w_2000`, `dn_72`),
                      store,
                      cache,
                      createNode,
                      createNodeId,
                    })

                    if (fileNode) {
                      fileNodeID = fileNode.id
                      await cache.set(webImageCacheKey, {
                        fileNodeID,
                      })
                    }
                  } catch (e) {
                    // Ignore
                    console.log(`ERROR ${e}`)
                  }
                }
                if (fileNodeID) {
                  return fileNodeID
                }
              }),
            )
            updated.localWebImages___NODE = updatedImages
          }
          console.log(updated)
          return { ...node, ...updated }
TypeError: Cannot read property 'internal' of null

  - infer-graphql-input-fields.js:254
    [escalade-sports]/[gatsby]/dist/schema/infer-graphql-input-fields.js:254:38

  - lodash.js:4925
    [escalade-sports]/[lodash]/lodash.js:4925:15

  - lodash.js:3010 baseForOwn
    [escalade-sports]/[lodash]/lodash.js:3010:24

  - lodash.js:4894
    [escalade-sports]/[lodash]/lodash.js:4894:18

  - lodash.js:9342 Function.forEach
    [escalade-sports]/[lodash]/lodash.js:9342:14

  - infer-graphql-input-fields.js:241 inferInputObjectStructureFromNodes
    [escalade-sports]/[gatsby]/dist/schema/infer-graphql-input-fields.js:241:5

  - build-node-types.js:91 _callee$
    [escalade-sports]/[gatsby]/dist/schema/build-node-types.js:91:36

  - next_tick.js:131 _combinedTickCallback
    internal/process/next_tick.js:131:7

  - next_tick.js:180 process._tickCallback
    internal/process/next_tick.js:180:9
stale? needs more info question or discussion

All 11 comments

@tbaustin can you provide a minimal reproduction repo of your code showing the error? What version of Gatsby are you running?

Using version 1.9.277. I will get the repo up soon sorry about that.

Here is the repo. Stay on the tbaustin branch. https://github.com/escaladesports/gatsby-source-salsify/tree/tbaustin

I am having to delete the local cache to get it to work if that helps any.

@Chuloo I found where this is breaking. The fileNodeID when cached is grabbed and skips the createRemoteFileNode making process. It is then assigned from the cacheMediaData.fileNodeID as you can see it is just returned and should be plugged into the array. This is where the error comes up, when the createRemoteFileNode process is skipped. Maybe I should just not do caching?

I am no pro at this, but I think the fileNodeID is referencing a Node that was created. So when we rerun the dev, the nodes aren't created and the fileNodeIDhas nothing to reference and this is where I think the error comes up?

I am not sure though, because this is how they are doing it in the wordpress-plugin so I would assume this should work just fine.

Anyone knows why this is happening? My page was working fine, I did an update on one of my pages inside of WordPress, after I re-run gatsby-develop, the page broke showing the same error
TypeError: Cannot read property 'internal' of null

gatsby: ^1.9.247 => 1.9.277

@tbaustin couldn't reproduce your error while running the repo you shared. Did you change anything? Stayed on the tbaustin branch.

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub issues, we have to clean some of the old issues as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Gatsby version and check if that solves the issue. Let us know if that works for you by adding a comment 馃憤

We have put this off for now so maybe with new gatsby it will fix this. I will re visit this later when I get some time! Until then I'm going to close this.

We had the same error message appearing and also resorted to removing the /.cache on start.
However, this is how we just fixed it:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dustinhorton picture dustinhorton  路  3Comments

signalwerk picture signalwerk  路  3Comments

rossPatton picture rossPatton  路  3Comments

jimfilippou picture jimfilippou  路  3Comments

kalinchernev picture kalinchernev  路  3Comments