javascript - Gatsby :在页面节点上调用 `touchNode` 抛出 'TypeError: locationAndPageResources.pageResources is undefined'

标签 javascript reactjs gatsby

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

TypeError: locationAndPageResources.pageResources is undefined

touchNode call:

// 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
              })
            }
        }
    }
  }))

预期结果

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

实际结果

enter image description here

最佳答案

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

关于javascript - Gatsby :在页面节点上调用 `touchNode` 抛出 'TypeError: locationAndPageResources.pageResources is undefined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58464105/

相关文章:

javascript - JQuery 不适用于 Joomla 3

node.js - 无法访问react和非node js后端(apache)服务器应用程序中的进程对象

reactjs - 如果我在 ReactJS 或 React Native 类的构造函数中使用 setState() 函数,会发生什么?

xml - 如果文件名中缺少 '.xml' 后缀,为什么 Chrome 会尝试下载/保存从 localhost 上的 gatsby 提供的 xml 文件,而不是在浏览器中显示?

javascript - 使用 JavaScript 检测和空间

javascript - 动态删除输入/DOM 错误

javascript - 从外部函数获取 Alfresco.util.Ajax.request response.json 数据

javascript - 多次调用 React 组件

javascript - 如何让 Gatsby Link 接收 props 作为参数并关闭点击光标

javascript - 路由更改时重新渲染脚本