Skip to content

nstringham/min-to-reproduce-typescript-import-problem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

in this example repo typescript correctly outputs the following javascript:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const myColor = "blue";
const myOtherColor = "red";
async function main() {
    const { printColor } = await import("dependency");
    printColor(myColor);
    printColor(myOtherColor);
}
main();

but incorrectly outputs the following errors

index.ts:1:28 - error TS1471: Module 'dependency' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.

1 import type { Color } from "dependency";
                             ~~~~~~~~~~~~

index.ts:5:28 - error TS1471: Module 'dependency' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.

5 const myOtherColor: import("dependency").Color = "red";
                             ~~~~~~~~~~~~