jimp: error TS2497: Module ''jimp'' resolves to a non-module entity and cannot be imported using this construct.
Hi,
I cannot import jimp with typescript, getting error. Details are below.
Expected Behavior
There shouldn’t be a compilation-time error.
Current Behavior
There is a compilation-time error.
error TS2497: Module ''jimp'' resolves to a non-module entity and cannot be imported using this construct. import * as jimp from 'jimp';
Also, import jimp from 'jimp'; doesn’t work because it imports the jimp into jimp_1 and becomes not usable…
Failure Information (for bugs)
Steps to Reproduce
Import jimp in a typescript file with import * as jimp from 'jimp';
- Jimp Version: ^0.3.9
- Operating System: MacOS
- Node version: v8.11.3
- TypeScript version: 3.0.1
Failure Logs
error TS2497: Module ''jimp'' resolves to a non-module entity and cannot be imported using this construct. import * as jimp from 'jimp';
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 22 (6 by maintainers)
Commits related to this issue
- TSC change to default export (#582) # What's Changing and Why fixes typescript build ## What else might be affected closes #581 ## Tasks - [x] Add tests - [x] Update Documentation - ... — committed to jimp-dev/jimp by hipstersmoothie 6 years ago
- Improve TypeScript declarations file (#660) * Improve TypeScript declarations file Addresses but does not fully close #581 Proper way to import is now `import * as X from 'jimp'` wherein X can ... — committed to jimp-dev/jimp by favna 6 years ago
- Improve TypeScript declarations file (#660) * Improve TypeScript declarations file Addresses but does not fully close #581 Proper way to import is now `import * as X from 'jimp'` wherein X can be w... — committed to jimp-dev/jimp by hipstersmoothie 6 years ago
I’ll add the ignore and create the PR but I’ll keep this issue open (will rewrite the commit message to remove the “resolves” part). I think the ideal case would be to rewrite the declarations file, specifically by extracting the
class Jimpfrom thenamespace Jimpand basically restructuring it entirely.Actually yes, I have since figured out that it works with
import Jimp = require('jimp');. It ended up being documented on typescriptlangExtract:
IMO it feels off to be using
requirein TypeScript but if we would like to useimport * as Jimp from 'jimp'or such a more ES6 Import/Export structure the definitions file would have to be rewritten a lot I’m afraid. I tried messing around myself a lot but I couldn’t get it that’s for sure :\