为页面构建静态 HTML 错误:错误:ENOENT:没有这样的文件或目录

Blo*_*gic 6 node.js typescript reactjs gatsby

gatsby build我的 gatsby 项目工作正常,并且也有 404 页面,但是我在成功完成构建过程后或在成功完成构建过程后打开浏览器时收到错误:

Building static HTML for pageserror: Error: ENOENT: no such file or directory
Run Code Online (Sandbox Code Playgroud)

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

Error: ENOENT: no such file or directory, stat '/project/public/404.html'
Run Code Online (Sandbox Code Playgroud)

Dha*_*era 5

// 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
Run Code Online (Sandbox Code Playgroud)


Blo*_*gic 4

解决方法1

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

  1. 尝试卸载build .cache、 和node_modules
  2. yarn add pkg.json npm install *
  3. 将所有必需的属性传递给所使用的所有页面中的布局(comp)。
  4. 运行gatsby develop之前的gatsby build

解决方法2

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

想在 Gatsby 中使用 React.lazy