Reputation: 179
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'
}
Upvotes: 1
Views: 5355
Reputation: 3145
Perhaps use a build script to set the permissions and then implement the next build.
Modifying the solution for EBS via this article:
#!/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
to make sure it runs on npm run build
"scripts": {
"build": "./build.sh"
}
Upvotes: 2