2

I'm trying to convert png to avif via Sharp, but I'm getting an error.

Code example

const image = sharp(`./images/img/original/image.png`)
    .avif({quality: 70, loseless: true})
    .toFile(`/images/img/avif/out.avif`)

Error

[Error: /images/img/avif/6znl4e0.avif: unable to open for write unix error: No such file or directory

How i can fix it?

Zorome
  • 106
  • 8
  • 2
    The output directory `/images/img/avif/` likely doesn’t exist. Note that as input you use `./images/`, which is very different from the `/images/` in the output! – Cris Luengo Jan 11 '23 at 01:57

1 Answers1

1

Sharp doesn't create a directory if it doesn't exist, You should check if the directory exists, and create it (using fs, for example).

Here's an answer from : Github

Abderazak Amiar
  • 776
  • 7
  • 22