unable to open for write unix error: No such file or directory. How to fix?

855 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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