首页 > 解决方案 > Gatsby:在页面节点上调用“touchNode”会引发“TypeError:locationAndPageResources.pageResources is undefined”

问题描述

当您转到希望缓存的页面时,在页面上调用 touchNode(来自源插件)会导致以下错误:

类型错误:locationAndPageResources.pageResources 未定义

touchNode 调用:

// Code here checks if the page node in Gatsby cache is the same version 
// as backend version. If so 'touch it' and don't recreate.
await Promise.all(result.data.pages.map(async page => {
    const pageCacheKey = `cache-${page.url}`
    const cacheResult = await pageRecords.getKey(pageCacheKey)
    if (cacheResult) {
        const node = pageNodes.find(node => {
            if (!node.context)
                return
            return node.context.url == page.url
        })

        if (node) {
            if (node.context.lastPublishedAt == page.lastPublishedAt) {
              pageRecords.setKey(pageCacheKey, localPublishedAt)
              return touchNode({
                nodeId: node.id
              })
            }
        }
    }
  }))

预期结果

页面节点应该持续存在而无需重新创建它(并且不需要后端)。

实际结果

在此处输入图像描述

标签: javascriptreactjsgatsby

解决方案


删除我的 index.js 文件后,我遇到了同样的错误。
我跑了gatsby clean,然后gatsby develop。这解决了问题。


推荐阅读