Skip to content

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

Closed
@BurtHarris

Description

@BurtHarris

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();

Activity

aluanhaddad

aluanhaddad commented on May 26, 2017

@aluanhaddad
Contributor

Yes it should! See #16093 🎉 🎉

fatcerberus

fatcerberus commented on May 27, 2017

@fatcerberus

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.

changed the title [-]Should default import check __esModule flag at runtime?[/-] [+]Please make default import check __esModule flag at runtime![/+] on May 27, 2017
BurtHarris

BurtHarris commented on May 27, 2017

@BurtHarris
Author

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

mhegazy

mhegazy commented on Aug 23, 2017

@mhegazy
Contributor

tracked by #16093

mhegazy

mhegazy commented on Sep 7, 2017

@mhegazy
Contributor

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

locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @BurtHarris@fatcerberus@aluanhaddad@mhegazy

        Issue actions

          Please make default import check __esModule flag at runtime! · Issue #16090 · microsoft/TypeScript