【问题标题】:Gatsby build path issuesGatsby 构建路径问题
【发布时间】:2020-07-30 21:50:04
【问题描述】:

在使用 gatsby-starter-wordpress-advanced 主题运行 gatsby 构建时遇到问题:

Error: ENOENT: no such file or directory, open 'C:\Users\Tobias\Desktop\Gatsby\gatsby-starter-wordpress-advanced\.template-cache\tmp-\.js'"

我认为这可能是路径的问题。路径应该看起来像:

writing tmp-new-page/ template: open '.template-cache/tmp-new-page.js'

见回购:https://github.com/henrikwirth/gatsby-starter-wordpress-advanced/blob/master/create/utils.js

第 53 行,您找到函数 createPageWithTemplate。我试过 console.log(page.uri) 看看发生了什么。它正确输出文件名。我也试过用 gatsby clean 来清除缓存。这似乎是某种反斜杠问题,路径末尾带有 \ .js 而不是 sample-page.js:

no such file or directory, open 'C:\Users\Tobias\Desktop\Gatsby\gatsby-starter-wordpress-advanced\.template-cache\sample-page\.js'

【问题讨论】:

  • 不幸的是 gatsby clean 没有做任何改变......仍然是同样的错误。
  • gatsby-clean 删除 .cache,但不是 .template-cache,据我所知。您是否尝试在再次运行之前手动删除它并重新安装您的依赖项 (rm -rf node_modules && yarn)?
  • 不幸的是仍然是同样的错误。我删除了 .template-cache 文件夹和 node_module 文件夹并运行了 npm install。
  • 很抱歉听到这个消息 - 您是否关注了 starter you're trying to use 所附的 tutorial?如果你这样做了,你可能想在初学者的 repo 上打开一个问题,因为这个问题似乎非常具体。或者,您可以在 Gatsby Starter Library 上查看其他入门者
  • 谢谢,罗宾。我刚刚浏览了博客文章教程的评论部分,似乎我不是唯一一个有问题的人:dev.to/ibjorn/comment/kj14 - 我会在初学者的 repo 上打开一个问题 :)

标签: reactjs wordpress path graphql gatsby


【解决方案1】:

问题已解决。该问题与 WPGraphQL WordPress 插件中的更新有关。必须更新路径,因为 page.uri 在新版本的 WPGraphQL 中是不同的。以前只是:some-page 现在是 /some-page/。

其次,在页面模板创建过程中,主题使用了 uri,因此,这弄乱了模板文件的路径。现在已将其切换到 page.slug 并进行了一些额外检查,以确保 frontPage 最终不会产生错误的路径。

启动主题的主分支已经更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    相关资源
    最近更新 更多