Skip to content

Please make default import check __esModule flag at runtime! #16090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BurtHarris opened this issue May 26, 2017 · 5 comments
Closed

Please make default import check __esModule flag at runtime! #16090

BurtHarris opened this issue May 26, 2017 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@BurtHarris
Copy link

BurtHarris commented May 26, 2017

TypeScript Version: 2.3.3
Input Code

My example is from a .js file with --allowJs. I've tried with and without --allowSyntheticDefaultImports, doesn't seem to make a difference.

import chai from 'chai'
const should = chai.should();

Expected behavior:
I think this should generate something like:

var chai_1 = require("chai");
var should = chai_1.__esModule ? chai_1.default.should() : chai_1.should();

Actual behavior:

var chai_1 = require("chai");
var should = chai_1.default.should();

babel's output

Here's what I've seen babel generate.  

var _chai = require('chai');
var _chai2 = _interopRequireDefault(_chai);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var should = _chai2.default.should();

workaround
Obviously I can work around this with a change to the input code:

import * as chai from 'chai'
const should = chai.should();
@aluanhaddad
Copy link
Contributor

Yes it should! See #16093 🎉 🎉

@fatcerberus
Copy link

It'll be great to see this change. I recently switched from Babel to TS as my transpiler for miniSphere as it's so much faster, but since I support both CommonJS and ES modules, my standard library is entirely CJS. The change broke a few modules as a result.

@BurtHarris BurtHarris changed the title Should default import check __esModule flag at runtime? Please make default import check __esModule flag at runtime! May 27, 2017
@BurtHarris
Copy link
Author

Updated title to make it a request rather than a question.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Aug 23, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Aug 23, 2017

tracked by #16093

@mhegazy
Copy link
Contributor

mhegazy commented Sep 7, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Sep 7, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants