Skip to content

Named exports missing from CommonJS module compiled with TS 4.4 and importHelpers: trueΒ #45813

@maxholman

Description

@maxholman

Bug Report

πŸ”Ž Search Terms

SyntaxError: Named export not found. The requested module is a CommonJS module, which may not support all module.exports as named exports, esm, exports, __exportStar, tslib

πŸ•— Version & Regression Information

  • This changed between versions 4.4 and 4.3

⏯ Playground Link

Playground links demonstrate the difference in compiled output between versions

Playground link with relevant code (4.4)

Playground link with relevant code (4.3)

Full reproduction repo and instructions

πŸ’» Code

From the above Playground link, 4.4 produces:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
(0, tslib_1.__exportStar)(require("fs"), exports);

4.3 produces:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("fs"), exports);

Note the use of the comma operator to unbind __exportStar. This seems to be new in 4.4 via more indirect calls for imported functions and #44624

πŸ™ Actual behavior

Named exports are missing when importing a CommonJS module compiled with Typescript 4.4 when importHelpers is true.

Setting importHelpers to false fixes this problem, but may result in a lot of duplicated code via tslib

πŸ™‚ Expected behavior

Named exports should either exist, whether I have importHelpers turned on or off.... or would be good this this was specifically documented as a breaking change.

(possibly) related: #45189

Metadata

Metadata

Assignees

Labels

FixedA PR has been merged for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions