生产中奇怪的 next.js 错误:ENOENT:没有这样的文件或目录(图像缓存)
我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
也许使用构建脚本来设置权限,然后实施下一个构建。
通过此 文章:
package.json
以确保它在npm run 上运行构建
Perhaps use a build script to set the permissions and then implement the next build.
Modifying the solution for EBS via this article:
package.json
to make sure it runs onnpm run build