我的next.js部署在AWS EC2上有问题。我是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'
}
发布于 2022-03-16 14:01:29
也许使用构建脚本来设置权限,然后实现下一个构建。
通过这个文章修改EBS的解决方案
#!/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
package.json
,以确保它在npm run build
上运行"scripts": {
"build": "./build.sh"
}
https://stackoverflow.com/questions/71490712
复制相似问题