question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error TS2497: Module ''jimp'' resolves to a non-module entity and cannot be imported using this construct.

See original GitHub issue

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';

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:22 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
favnacommented, Nov 19, 2018

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.

1reaction
favnacommented, Nov 11, 2018

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 :\

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does "... resolves to a non-module entity and cannot be ...
Module "MyClass" resolves to a non-module entity and cannot be imported using this construct. and when trying to call fn(). Cannot invoke an ......
Read more >
error TS2497: Module ''jimp'' resolves to a non-module entity and ...
Hi,. I cannot import jimp with typescript, getting error. Details are below. Expected Behavior. There shouldn't be a compilation-time error.
Read more >
Typescript – What does “… resolves to a non-module entity ...
This gives me errors when trying to use new. Module "MyClass" resolves to a non-module entity and cannot be imported using this construct....
Read more >
importing non-module python files (intermediate) anthony ...
today I show how to import non- modules in python -- either with invalid module names or files which aren't .py at all!playlist: ......
Read more >
Definitely Typed
Once you've tested your definitions with real code, make a PR then follow the ... error TS2497: Module 'foo' resolves to a non-module...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found