【问题标题】:Building static HTML for pageserror: Error: ENOENT: no such file or directory为 pageserror 构建静态 HTML:错误:ENOENT:没有这样的文件或目录
【发布时间】:2020-11-08 16:20:42
【问题描述】:

我的 gatsby 项目运行良好,也有 404 页面,但是我在 gatsby build 期间收到错误,或者在成功完成构建过程后打开浏览器:

Building static HTML for pageserror: Error: ENOENT: no such file or directory

如果我在gatsby build 时间内没有收到错误,那么我必须在运行gatsby serve 并打开浏览器时进入浏览器:

Error: ENOENT: no such file or directory, stat '/project/public/404.html'

【问题讨论】:

  • 尝试添加404页面
  • @BloodyLogic 当你运行gatsby clean,然后运行gatsby buildgatsby serve时发生了什么?
  • @ShinaBR2 已经尝试过 rm -rf node_module .cache public 但没有帮助我,不过它在前一段时间就可以工作了!

标签: node.js reactjs typescript gatsby


【解决方案1】:

如果上述答案对你不起作用(对我不起作用),Gatsby 会在 ~/.config/gatsby/config.json 处保留一份 config.json 副本。

删除文件使它对我有用。

Relevant Github issue 来自 Gatsby 存储库

【讨论】:

    【解决方案2】:
    // clean gatsby cache
    gatsby clean
    // delete node modules, cache and public folder.
    rm -rf node_module .cache public
    // reinstall node modules
    npm install
    // run gatsby in develop mode
    gatsby develop
    // build the gatsby project
    npm run build
    // serve the building project.
    gatsby serve
    

    【讨论】:

    • 即使只是 gatsby clean 也能解决这类问题。 另外,我建议您以 gatsby develop -H 0.0.0.0 的形式运行您的开发命令,这允许在连接时进行实时移动测试同一个网络。
    【解决方案3】:

    解决方法 1

    如果不这样做,请在 pages 文件夹中添加 404.js404.tsx 文件

    1. 尝试卸载build.cachenode_modules
    2. yarn add pkg.jsonnpm install *
    3. 将所有必需的道具传递给所有使用过的页面中的布局 (comp)。
    4. gatsby build 之前运行gatsby develop

    解决方法 2

    可能您在不支持服务器端渲染的组件中使用了React.lazy suspense,您需要以任何可能的方式将其删除。 然后试试这个应该可以!

    Want to use React.lazy in Gatsby

    【讨论】:

      猜你喜欢
      • 2021-10-08
      • 1970-01-01
      • 2017-10-07
      • 2021-04-09
      • 1970-01-01
      • 1970-01-01
      • 2019-03-09
      • 2017-12-28
      • 2022-01-16
      相关资源
      最近更新 更多