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

Most upvoted comments

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 Jimp from the namespace Jimp and 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 typescriptlang

Extract:

Both CommonJS and AMD generally have the concept of an exports object which contains all exports from a module.

They also support replacing the exports object with a custom single object. Default exports are meant to act as a replacement for this behavior; however, the two are incompatible. TypeScript supports export = to model the traditional CommonJS and AMD workflow.

The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.

When exporting a module using export =, TypeScript-specific import module = require("module") must be used to import the module

IMO it feels off to be using require in TypeScript but if we would like to use import * 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 :\