-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 2.9.2, 3.0.0-dev.20180703
Search Terms:
resolveJsonModule, esModuleInterop
Code
import * as test from './test.json';
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "es2017",
"lib": ["es2017"],
"strict": true,
"sourceMap": true,
"noEmitOnError": true,
"baseUrl": ".",
"resolveJsonModule": true,
"outDir": "out"
}
}
Expected behavior:
No errors.
Actual behavior:
Compile error:
$ tsc
test.ts:1:23 - error TS2497: Module '"/home/kostya/tmp/resolve-json-test/test"' resolves to a non-module entity and cannot be imported using this construct.
1 import * as test from './test.json';
~~~~~~~~~~~~~
When I add esModuleInterop
option to tsconfig.json
:
diff --git a/tsconfig.json b/tsconfig.json
index 7f1afb8..e949135 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -9,6 +9,7 @@
"noEmitOnError": true,
"baseUrl": ".",
"resolveJsonModule": true,
+ "esModuleInterop": true,
"outDir": "out"
}
}
and change import statement to:
diff --git a/test.ts b/test.ts
index 07bb9b7..dddcffb 100644
--- a/test.ts
+++ b/test.ts
@@ -1 +1 @@
-import * as test from './test.json';
+import test from './test.json';
it works. But with esModuleInterop
option I need to change many imports in my project, which is undesirable.
Playground Link:
Related Issues:
xinthose, garronej, shahrishabhptechnical, medmunds, paxperscientiam and 20 more
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue