生产中奇怪的 next.js 错误:ENOENT:没有这样的文件或目录(图像缓存)

发布于 2025-01-14 14:36:04 字数 938 浏览 2 评论 0原文

我在 AWS EC2 上部署 next.js 时遇到问题。我npm run build然后npm run start,它工作得很好。此时,正如预期的那样,缓存中没有 webp 图像。然后我从浏览器加载网页,它工作正常。然而,当我有时加载页面时,它似乎随机崩溃。我收到上面的错误。似乎 webp 图像在某个时刻被从缓存中删除,并导致错误?有什么建议吗?

完整的错误是:

Error: ENOENT: no such file or directory, open '/home/ec2-user/prowash/pro-wash-site/.next/cache/images/7P-NdCEO6XWRTvqPItIV6CN1db-7IkBJw9kp3M5VafQ=/0.1647390677641.UEF7UxgKHha+us8b5ahYFWZH70qZHTAu2uyVPlYT7Hs=.webp'
Emitted 'error' event on ReadStream instance at:
    at emitErrorNT (node:internal/streams/destroy:164:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/ec2-user/prowash/pro-wash-site/.next/cache/images/7P-NdCEO6XWRTvqPItIV6CN1db-7IkBJw9kp3M5VafQ=/0.1647390677641.UEF7UxgKHha+us8b5ahYFWZH70qZHTAu2uyVPlYT7Hs=.webp'
}

I'm having issues with my next.js deployment on AWS EC2. I npm run build and then npm run start, and it works fine. At that point, there are no webp images in the cache, as expected. Then I load the webpage from my browser ,and it works fine. However it randomly seems to crash when i load the page sometimes. And i get the error above. It seems like the webp image is being deleted from the cache at some point, and causing an error? Any suggestions?

The full error is:

Error: ENOENT: no such file or directory, open '/home/ec2-user/prowash/pro-wash-site/.next/cache/images/7P-NdCEO6XWRTvqPItIV6CN1db-7IkBJw9kp3M5VafQ=/0.1647390677641.UEF7UxgKHha+us8b5ahYFWZH70qZHTAu2uyVPlYT7Hs=.webp'
Emitted 'error' event on ReadStream instance at:
    at emitErrorNT (node:internal/streams/destroy:164:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/ec2-user/prowash/pro-wash-site/.next/cache/images/7P-NdCEO6XWRTvqPItIV6CN1db-7IkBJw9kp3M5VafQ=/0.1647390677641.UEF7UxgKHha+us8b5ahYFWZH70qZHTAu2uyVPlYT7Hs=.webp'
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木緿 2025-01-21 14:36:04

也许使用构建脚本来设置权限,然后实施下一个构建。

通过此 文章

  1. 一个 Build.sh 脚本,在部署之前设置权限
#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e


# building the Next.js application
npm run next:build

# creating the build/cache/images folder and give it
# the read/write permissions
mkdir -p .next/cache/images
chmod -R 666 .next/cache/images
  1. 添加到 package.json 以确保它在 npm run 上运行构建
"scripts": {
  "build": "./build.sh"
}

Perhaps use a build script to set the permissions and then implement the next build.

Modifying the solution for EBS via this article:

  1. A Build.sh script that sets permissions before its deployed
#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e


# building the Next.js application
npm run next:build

# creating the build/cache/images folder and give it
# the read/write permissions
mkdir -p .next/cache/images
chmod -R 666 .next/cache/images
  1. Addition to package.json to make sure it runs on npm run build
"scripts": {
  "build": "./build.sh"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文