Skip to content

Consider removing unstable "node:module".stripTypeScriptTypes to reduce baseline SEA binary size #57744

Description

@dsherret

I think it would be beneficial to consider not stabilizing stripTypeScriptTypes and instead require users to specify a dependency on swc or whatever library they wish.

Reason: This enables Node single executable applications to stay small and not have every binary have a dependency on swc. Instead users can choose to increase their binary size by specifying a dependency only when they need it and not always.

Sure, current design constraints might mean it's currently always required, but in the future work could be done on Node to make this not the case. For example in Deno our single executable applications are custom smaller binaries that do not include swc and we do all the transpiling work up-front when compiling instead of at runtime.

An alternative to this could be making it opt-in to include this API in single executable applications, but overall I think it's much simpler to just require users to specify a dependency because this is a niche use case and also it makes code work the same way across different versions of Node.

Activity

  1. RaisinTen commented on Apr 5, 2025

    @RaisinTen
    Member

    How much does swc add to the binary size?

  2. RaisinTen commented on Apr 5, 2025

    @RaisinTen
    Member
  3. marco-ippolito commented on Apr 5, 2025

    @marco-ippolito
    Member

    Around 3MB

  4. marco-ippolito commented on Apr 5, 2025

    @marco-ippolito
    Member

    Also if you drop amaro its not possible to use type stripping either, not just module.stripTypeScriptTypes

  5. dsherret commented on Apr 5, 2025

    @dsherret
    Author

    Also if you drop amaro its not possible to use type stripping either

    It is if it's re-architected to be done ahead of time when creating the executable. Not sure if it's done already, but that's what we do in Deno.

    An additional benefit is SEAs start faster because they don’t need to transpile on each run.

  6. RaisinTen commented on Apr 6, 2025

    @RaisinTen
    Member

    There might be some confusion here - node sea doesn't have native typescript support yet. When I implement it, I agree that transpiling the code ahead of time and injecting that code is better than injecting the original code and transpiling on each run.

    Marco is probably referring to the other existing ways of doing type stripping in node which is separate from node sea. Those won't work if we drop amaro from node. Maybe it could be made to work if node uses amaro as an optional node_modules dep but I'll let Marco answer that.

  7. dsherret commented on Apr 6, 2025

    @dsherret
    Author

    Ah, ok I’m not suggesting to remove type stripping from node itself, but just the user facing runtime API for the reasons stated above.

  8. marco-ippolito commented on Apr 6, 2025

    @marco-ippolito
    Member

    If we decide not to support typescript in SEA then it makes sense not to include amaro in it and document that module.stripTypeScriptTypes is not available. But the api can be stable, the experimental status is not related to the availability in sea.

  9. dsherret commented on Apr 6, 2025

    @dsherret
    Author

    By not stabilizing, I was implying to remove the public runtime API everywhere, but I didn’t make that explicit. I’ll update the title.

  10. changed the title [-]Consider not stablizing `"node:module".stripTypeScriptTypes` to reduce baseline SEA binary size[/-] [+]Consider removing unstable `"node:module".stripTypeScriptTypes` to reduce baseline SEA binary size[/+] on Apr 6, 2025
  11. marco-ippolito commented on Apr 6, 2025

    @marco-ippolito
    Member

    I disagree we should remove it from everywhere
    We can make it unavailable in SEA by documenting that amaro is not available.

  12. dsherret commented on Apr 6, 2025

    @dsherret
    Author

    I don’t think that’s viable because over time users will complain that certain things don’t work in SEA. Also, by adding this API, other execution environments other than SEA that offer node compatibility are being bloated (ex. workerd).

    What’s the issue with users just including the dependency the classic way if they need it? This use case is niche.

  13. marco-ippolito commented on Apr 6, 2025

    @marco-ippolito
    Member

    I'm working on other APIs that rely on amaro (#57731)
    I think its fair to add a SEA config to enable/disable amaro so users can opt in/out.

    The request of removing an API because of other runtimes feels wild 😄

  14. dsherret commented on Apr 6, 2025

    @dsherret
    Author

    The request of removing an API because of other runtimes feels wild 😄

    It was a secondary point and not the main point. For example personally in Deno we use swc.

    Edit: In response to @ovflowd below, I know Amaro is swc. My point with this comment is that Deno and Node have a similar underlying unfrasturcture.

  15. marco-ippolito commented on Apr 6, 2025

    @marco-ippolito
    Member

    I see your point, actually having a way to opt-in/opt out some modules in SEA would be beneficial, like amaro, crypto, npm (mentioning those because I know its possible to build node without them).

  16. dsherret commented on Apr 7, 2025

    @dsherret
    Author

    That's more reasonable if it's possible and feasible to do that.

    Side note: this overall trend in JS runtimes to just have built-in APIs for stuff that could be a library is not great for the long term health of the JS ecosystem in my opinion. So much bloat, runtime specific code, and extra complexity across the ecosystem for functionality that could have easily been specified as a dependency and be decoupled from the runtime where it would work in even old versions of node.js.

  17. RaisinTen commented on Apr 7, 2025

    @RaisinTen
    Member

    Opting out of those modules requires building node from source. While it's definitely possible, SEA builders will find it inconvenient to build node from source.

  18. ovflowd commented on Apr 7, 2025

    @ovflowd
    Member

    The request of removing an API because of other runtimes feels wild 😄

    It was a secondary point and not the main point. For example personally in Deno we use swc.

    Amaro is swc.

  19. ovflowd commented on Apr 7, 2025

    @ovflowd
    Member

    This is more a discussion of allowing SEA to be ahead-of-time and interpolating what node: namespaces are being used within the binary you are generating. Which is a nice idea, but quite challenging as SEA is CJS-only and that is not statically analyzable at the moment due to the nature of require.

  20. ljharb commented on Apr 7, 2025

    @ljharb
    SponsorMember

    (require is precisely as statically analyzeable as import, given that both can be used statically or dynamically)

  21. ovflowd commented on Apr 7, 2025

    @ovflowd
    Member

    (require is precisely as statically analyzeable as import, given that both can be used statically or dynamically)

    I never did imply that it is less or more than import. Just saying that it is not fully statically analyzeable 😅

  22. joyeecheung commented on Apr 8, 2025

    @joyeecheung
    Member

    FWIW, the biggest blob in the Node.js binary isn't something like amaro, but the full ICU data (at least 30M), even if you do not use Intl or prefer to use the system ICU instead of the bundled one (the bundled data may actually be worse than system one, or out of date when there's e.g. timezone changes). If we are talking about reducing the baseline binary size, that leads to the general question about how to remove these components that people may or may not use. For example, changing the build process so that these extra components are appended to the final binary and can be removed easily by binary surgery tools like postject.

  23. ovflowd commented on Apr 8, 2025

    @ovflowd
    Member

    FWIW, the biggest blob in the Node.js binary isn't something like amaro, but the full ICU data (at least 30M), even if you do not use Intl or prefer to use the system ICU instead of the bundled one (the bundled data may actually be worse than system one, or out of date when there's e.g. timezone changes). If we are talking about reducing the baseline binary size, that leads to the general question about how to remove these components that people may or may not use. For example, changing the build process so that these extra components are appended to the final binary and can be removed easily by binary surgery tools like postject.

    Makes sense to me.

  24. github-actions commented on Apr 20, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 210 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  25. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Apr 20, 2026
  26. github-actions commented on May 20, 2026

    @github-actions
    Contributor

    This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 240 days).
    If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

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

    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.strip-typesIssues and PRs related to TypeScript type stripping.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions