Skip to content
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

Not work well with TypeScript export default as output #69

Open
chentsulin opened this issue Jun 8, 2022 · 2 comments
Open

Not work well with TypeScript export default as output #69

chentsulin opened this issue Jun 8, 2022 · 2 comments
Labels
edge case wontfix This will not be worked on

Comments

@chentsulin
Copy link

chentsulin commented Jun 8, 2022

Hi,

TypeScript export default as syntax seems not working with this module. Considering the following TS code:

export { default as fs } from 'fs'; 

Test its output with cjs-module-lexer:

const { parse } = require('cjs-module-lexer');

const result = parse(`
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fs = void 0;
var fs_1 = require("fs");
Object.defineProperty(exports, "fs", { enumerable: true, get: function () { return __importDefault(fs_1).default; } });
`);

console.log(result);

It prints:

{ exports: [ '__esModule' ], reexports: [] }

fs do not be considered as exports in the above case.

And I also figure out that changing the place of the __importDefault call

var fs_1 = require("fs");
Object.defineProperty(exports, "fs", { enumerable: true, get: function () { return __importDefault(fs_1).default; } });

to something like this one (what babel does):

var fs_1 = __importDefault(require("fs"));
Object.defineProperty(exports, "fs", { enumerable: true, get: function () { return fs_1.default; } });

The result will become:

{ exports: [ '__esModule', 'fs'], reexports: [] }

Is this an expected behavior?

Ref:

@qnighy
Copy link

qnighy commented Jun 15, 2022

Experiencing the same problem. react-share@4.4.0 is one such package and has no named exports except __esModule when imported from .mjs.

@chentsulin
Copy link
Author

@guybedford Could you take a look on this? Is the behavior expected?

@guybedford guybedford added enhancement New feature or request edge case wontfix This will not be worked on and removed enhancement New feature or request labels Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
edge case wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants