Skip to content

5.5.0 regression - Named exports of functions are not emitted for CommonJS #58473

Closed

Description

🔎 Search Terms

commonjs export

🕗 Version & Regression Information

  • This changed between versions 5.4.5 and 5.5.0

⏯ Playground Link

https://www.typescriptlang.org/play/?target=7&module=1&isolatedModules=true&verbatimModuleSyntax=false&ts=5.5.0-beta#code/GYVwdgxgLglg9mABMOcAUBKAXIgbnGAE0QG8AoAXzLIFMAPABzgCcpSzFPlUAaSgbjJA

💻 Code

function foo(): void {
}

export {
    foo,
};

🙁 Actual behavior

ts 5.5.0-beta and 5.5.0-dev-20240508 both emit:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = void 0;
function foo() {
}

note missing last line

🙂 Expected behavior

ts 5.4.5 emit

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = void 0;
function foo() {
}
exports.foo = foo;

Additional information about the issue

No response

Activity

  1. changed the title [-]Named exports of functions are not emitted for CommonJS[/-] [+]5.5.0 regression - Named exports of functions are not emitted for CommonJS[/+] on May 8, 2024
  2. Knagis commented on May 8, 2024

    @Knagis
    ContributorAuthor

    the problem shows up only with functions. exporting classes or variables via export { foo } work fine. also export function foo() {} works fine.

  3. jakebailey commented on May 9, 2024

    @jakebailey
    Member

    Most likely this was #57669 (you could try using https://www.npmjs.com/package/every-ts to bisect and verify).

  4. Knagis commented on May 9, 2024

    @Knagis
    ContributorAuthor

    Bisect confirms that it is the cause

    881f449a8a10839db5d535c3a407621d53c78666 is the first bad commit
    commit 881f449a8a10839db5d535c3a407621d53c78666
    Author: Ron Buckton
    Date:   Wed Mar 6 18:43:59 2024 -0500
    
        Hoist function exports to top of module body in CJS/AMD/UMD (#57669)
    
  5. jakebailey commented on May 9, 2024

    @jakebailey
    Member

    Yeah, the issue appears to be that collectExternalModuleInfo doesn't do the same thing it does for function declarations when processing export declarations.

  6. Knagis commented on May 28, 2024

    @Knagis
    ContributorAuthor

    Jake Bailey (@jakebailey) is there a chance the fix for this could be merged before 5.5.1?

  7. jakebailey commented on Aug 20, 2024

    @jakebailey
    Member

    What version of TS is the above output from? Is that expected output? Unexpected output?

    That output is assigning mockedClassComponent to the exports, not omitting it entirely, so I don't think what you've described is the same thing (and shows that the current state is working).

  8. meriouma commented on Aug 20, 2024

    @meriouma

    Sorry, I think I was tracking the wrong issue.

  9. locked as resolved and limited conversation to collaborators on Oct 22, 2025
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions