Niels-IO / next-image-export-optimizer

Use Next.js advanced <Image/> component with the static export functionality. Optimizes all static images in an additional step after the Next.js static export.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when no public/images folder exists

FreTimmerman opened this issue · comments

I only have statically imported images, so i don't have a folder public/images

when running the script, all optimizations seem to be performed correctly, however at the end it reports an error:

Error: ENOENT: no such file or directory, open 'public/images/next-image-export-optimizer-hashes.json'
    at Object.openSync (node:fs:600:3)
    at Object.writeFileSync (node:fs:2221:35)
    at nextImageExportOptimizer (node_modules/next-image-export-optimizer/dist/optimizeImages.js:376:8) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: 'public/images/next-image-export-optimizer-hashes.json'
}

it means the hashes are never saved, and every time i run yarn export it will once again optimize all images, taking some time...

only once i manually create the folder public/images all is well 👍

i suggest you first check for the folder's existence before trying to write to it...

commented

Thanks for the bug report and the PR! I am about to merge it 👍