Description
Cropper version
2.0.0
Link to minimal reproduction
Steps to reproduce
Default-import cropperjs in a TypeScript project with "module": "Node16" or "module": "NodeNext" in tsconfig.json
What is expected?
TypeScript recognizes the default import as the Cropper class.
What is actually happening?
TypeScript recognizes the default import as a namespace (with {default: Cropper })
Any additional comments?
Can you add "type": "module" to the package.json?
Consider this code:
import Cropper from "cropperjs";
let x: Cropper = new Cropper(document.createElement("img"));
With module: "es2022" in the tsconfig.json it works. With module: "node16" it fails. Try this playground example and change the module resolution via TS Config -> Module.
The error is:
Cannot use namespace 'Cropper' as a type.
This expression is not constructable.
I.e. it expects the default imported Cropper to be {default: Cropper}.
This can be solved by setting "type": "module" in the package.json of cropperjs. I tried adding this via yarn patching cropperjs and can confirm it worked.
There are various reasons for setting module to node16 / nodenext, e.g. support for the exports field in the package.json
The only option for that type error is to access default manually, i.e.
import Cropper from "cropperjs";
let x: Cropper.default = new Cropper.default(document.createElement("img"));
But that's going to fail with pretty much every bundler out there, since they recognize it as an ESM module without "type": "module".
primefaces/primefaces#13456