esModuleInterop is not supported
See original GitHub issueWhen I run tsickle with esModuleInterop
, tsickle produces the wrong javascript, with a regular require
instead of goog.require
.
Repro steps:
npm install typescript@~3.5.3 tsickle@0.37.0
I wish I could use tsickle 0.37.1, but unfortunally the npm package doesn’t have a binary (or a main.js file).
tsconfig.json:
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
}
}
a.ts:
import * as b from './b';
b.foo();
b.ts:
export function foo() {}
Generated a.js:
goog.module('a');
var module = module || { id: 'a.ts' };
const tsickle_b_1 = goog.requireType("b");
const b = __importStar(require("./b"));
b.foo();
If I don’t use import * as ...
then the emitted JS is correct.
esModuleInterop
is now one of the default flags generated when running tsc --init
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
esModuleInterop not working for certain libraries · Issue #27293
So there's an inconsistency between TypeScript's compile-time and runtime behavior, and the only option to fix it may be to allow a default ......
Read more >Understanding esModuleInterop in tsconfig file - Stack Overflow
Problem statement. Problem occurs when we want to import CommonJS module into ES6 module codebase. Before these flags we had to import ...
Read more >TSConfig Option: esModuleInterop - TypeScript
By default (with esModuleInterop false or not set) TypeScript treats ... then TypeScript allowed for the import to be treated as a function...
Read more >Module can only be default-imported using esModuleInterop flag
The error "Module can only be default-imported using esModuleInterop flag" occurs when we try to import a CommonJS module into an ES6 module....
Read more >Typescript language server does not use compilerOptions in ...
1/index"' can only be default-imported using the 'esModuleInterop' flag" even though esModuleInterop is set to true in tsconfig.json file. Attachments 5.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any update on this issue? I’m sure tons of people out there would love to use tsickle with their TypeScript projects, but not supporting “esModuleInterop” seems to be a show-stopper.
In my particular case, my project has ES6-style import statements on JSON files, so it requires “esModuleInterop” to be set to true or it won’t even compile. As far as I know, this kind of this is the recommended solution / best practice for TypeScript, e.g. the highest upvoted answer here: https://stackoverflow.com/a/50830840
Somehow my comment disappeared from the thread. I tried tscc and got the same error.
Note that esModuleInterop is now one of the default flags when you use
tsc --init
, so this is going to be frustrating for people starting to use tsickle for the first time. Erroring on start for unsupported tsconfig flags sounds like a good first step.