javascriptangularimagetypescript

Jimp: image processing fail on module usage


I am unable to use Jimp.

installed: npm install --save jimp //OK

imported: import * as Jimp from 'jimp'; //OK

usage Jimp.read(someImage) //fail with error

Uncaught (in promise): Error: Node's Buffer() not available


Solution

  • This is a breaking change in Jimp 0.2.28, and the current solution is to revert to 0.2.27. However, as you've noted in the comments, import will not work for Jimp@0.2.27 for TypeScript.

    It looks like with TypeScript, require and import accomplish two different things. So with import, you need to have a declaration file declaring the module so it can determine what the module is at compile-time. If you don't have that, TypeScript will not be able to resolve it at all. require happens at runtime, so TypeScript is uninvolved (and you won't have type information with required modules).

    This answer explains it better than I could.

    It looks like Jimp 0.2.27 does not define a .d.ts file while 0.2.28 does. I'm unsure why they included so many changes in one patch.