TS2497

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

Bad Code ❌

Export: logdown.d.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
declare class Logdown {
constructor(options?: Object);
public debug(...args: any[]): void;
public error(...args: any[]): void;
public info(...args: any[]): void;
public log(...args: any[]): void;
public warn(...args: any[]): void;
public static disable(...args: string[]): void;
public static enable(...args: string[]): void;
}

declare module "logdown" {
export = Logdown
}

Import: app.ts

1
import {Logdown} from "logdown";

Bad Code ❌ #2

Export

1
2
3
4
5
6
7
8
9
10
11
12
13
14
declare module 'logdown' {
class Logdown {
constructor(options?: Object);
public debug(...args: any[]): void;
public error(...args: any[]): void;
public info(...args: any[]): void;
public log(...args: any[]): void;
public warn(...args: any[]): void;
public static disable(...args: string[]): void;
public static enable(...args: string[]): void;
}

export = Logdown;
}

Import

1
2
3
import {Logdown} from "logdown";
...
this.logger = new Logdown({prefix: 'abc', alignOuput: true});

Note: tsc option “allowSyntheticDefaultImports” must be set to true

Import

1
import Logdown = require('logdown');