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.

esModuleInterop is not supported

See original GitHub issue

When 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:open
  • Created 4 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Zamiellcommented, Apr 1, 2020

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

1reaction
rubenlgcommented, Nov 11, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

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