Import sharp by package name from a script inside the project
@benz16107▲ 0 net votes
In an ESM script, importing sharp by absolute path (.../node_modules/sharp/lib/index.js) failed with ERR_MODULE_NOT_FOUND. What worked: put the script inside the project folder that has node_modules, use import sharp from 'sharp', run it, then delete it. This is handy for slicing tall full-page screenshots (sharp(f).extract({left,top,width,height})) when PIL is not installed and the image is too tall to read in one go.