Skip to content

Unflagging Type Stripping in Node.js v22 #37

Closed

Description

@marco-ippolito

I created this issue to track breakages that prevent unflagging type stripping in Node.js v22.
In October Node.js v22 will transition to maintainance so it means it will not be possible to backport.
Since type stripping is already enabled in Node.js v24, these libraries are not compatible with it and they eventually need to fix this issue.

The breaking change stems from libraries assuming the internal require.extensions['.ts'] is registered by ts-node while in Node >23 is registered by Type Stripping.

Let's try to track all the libraries affect and try to fix them before Node.js v22 goes maintainance.

(If you know a library that breaks drop a comment) @nodejs/typescript

Activity

  1. changed the title [-]Unflagging Type Stripping in Node v22[/-] [+]Unflagging Type Stripping in Node.js v22[/+] on Jun 9, 2025
  2. joyeecheung commented on Jun 9, 2025

    @joyeecheung
    Member

    The breaking change stems from libraries assuming the internal require.extensions['.ts'] is registered by ts-node while in Node >23 is registered by Type Stripping.

    Is that the only relevant breakage? AFAIR you don't actually need to insert require.extensions['.ts'] to support it, you can just catch it in the .js handler which, according to the funny algorithm we use to decide which handler to use, will be used as a fallback to handle .ts if there's none that's already registered by the users. I did that for .mjs but I left .ts etc. as-is because I don't know whether TypeScript support really needed it nodejs/node#55590

  3. joyeecheung commented on Jun 9, 2025

    @joyeecheung
    Member

    Or if you want to see how I did it for just .mjs without interfering with .ts paths, see the commit adapted for v20.x joyeecheung/node@1c3f307

    EDIT: actually now I realized that this commit has gone missing in the v20.x backport - although I think the breakage is less significant with .mjs because the biggest user of it (the esm package) had been broken on v18.x for other reasons a long time ago. We might still want to backport it to v20.x at some point even though I haven't seen anyone complained.

  4. ljharb commented on Jun 9, 2025

    @ljharb
    SponsorMember

    It would be very unfortunate if Object.keys(require.extensions) didn't map to the exact list of known requireable extensions, though.

  5. joyeecheung commented on Jun 9, 2025

    @joyeecheung
    Member

    I think they haven't been consistent for many years (.cjs has not been in the map, maybe never? That was how I found out about this funny algorithm in the first place)

  6. marco-ippolito commented on Jun 9, 2025

    @marco-ippolito
    MemberAuthor

    If we agree to remove '.ts' from require.extensions that would fix the breaking change. Although it would make it inconsistent and should probably be removed as an api. If that's ok I can open a PR

  7. ljharb commented on Jun 9, 2025

    @ljharb
    SponsorMember

    A lot of tooling, lots of which can't ever be updated, will break if require.extensions is ever removed, so i'm not sure that'll ever happen.

  8. marco-ippolito commented on Jun 10, 2025

    @marco-ippolito
    MemberAuthor

    This PR should fix all these issues except mocha: nodejs/node#58657

  9. marco-ippolito commented on Jun 25, 2025

    @marco-ippolito
    MemberAuthor

    I tested against all the projects I found to be broken and v24.3.0 fixes them. I think it's safe to backport now

  10. arthur-fontaine commented on Jul 11, 2025

    @arthur-fontaine
  11. marco-ippolito commented on Jul 11, 2025

    @marco-ippolito
    MemberAuthor

    This is not a typescript related problem, as it happens in .js files too, but it works if you use .mjs or .mts extension. Its a esm detection problem, please open an issue on nodejs/node

  12. arthur-fontaine commented on Jul 11, 2025

    @arthur-fontaine

    Oh sorry, you’re right. I didn’t test it with JS because I assumed it was valid syntax and that Node would handle it properly. I’ve hidden my comment. Thank you!

  13. alexsch01 commented on Jul 16, 2025

    @alexsch01

    Made https://github.com/alexsch01/tsnode as a wrapper with typechecking for nodejs 24.3.0+ for now

    When it is unflagged for v22, I'll consider adding support for it in my tool
    (definitely will add support if/when the experimental warning is removed for v22)

  14. marco-ippolito commented on Aug 1, 2025

    @marco-ippolito
    MemberAuthor

    Type stripping has been unflagged in v22.18.0 nodejs/node#59256. I'm gonna leave this issue open for a few days then we can consider it done unless have to revert it

  15. marco-ippolito commented on Oct 6, 2025

    @marco-ippolito
    MemberAuthor

    I'm gonna close this as it has been unflagged for quite some time now

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