Jimp: image processing fail on module usage
Solution 1:
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 [email protected] 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 require
d 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.
Solution 2:
Get the compiler error, when doing import * as Jimp from 'jimp';
.
Turns out Jimp
's @type file uses export =
syntax, So have to import like below:
import Jimp = require('jimp');