(node.js module) sharp image processor keeps source file open, unable to unlink original after resize
I initially was thrown by your use of forward slashes, assuming that you'd be using a Unix-type OS, where calling unlink
of a file that is still open generally isn't a problem.
However, on Windows, I think that open files are usually protected from being deleted, and this issue describes a similar problem, and also a solution: internally, sharp
maintains a cache of (open) files, which will block the original file from being deleted.
If you disable that cache, the problem should be fixed:
// add this at the top of your code
sharp.cache({ files : 0 });
Documented here.
EDIT: as noted in some of the comments, the code above may not fix the problem. Instead, use this:
sharp.cache(false);