Skip to content

node 22.18 breaks npm package because of experimental-strip-types enabled #59364

Description

@tbowmo

Version

v22.18.0

Platform

Linux / Windows / Azure devops build agents

Subsystem

No response

What steps will reproduce the bug?

After updating to node22.18 we see issues with builds. Looking through the change notes, I see that it now has enabled an experimental feature, and we now to have to add --no-experimental... to the command line in order to run our code in nodejs.

How often does it reproduce? Is there a required condition?

consistently failure in our CI pipelines unless --no-experimental-strip-types is added to node cli

What is the expected behavior? Why is that the expected behavior?

minor releases should not add experimental features to an existing lts version

What do you see instead?

Failing builds using node 22.18 (working fine with node 22.17)

Additional information

No response

Activity

  1. added
    strip-typesIssues and PRs related to TypeScript type stripping.
    on Aug 5, 2025
  2. targos commented on Aug 5, 2025

    @targos
    Member

    @nodejs/typescript

  3. JakobJingleheimer commented on Aug 5, 2025

    @JakobJingleheimer
    Member

    What errors? What reproduces them?

  4. rmlearney-digicatapult commented on Aug 5, 2025

    @rmlearney-digicatapult

    Happening here too:

    nvm use 22 -> 22.18

    Then we just run our unit tests as usual, or in CI

    Doesn't happen with 22.17.1

    Exception during run: Error [ERR_INTERNAL_ASSERTION]: Unexpected status of a module that is imported again after being required. Status = 0
    This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
    Please open an issue with this stack trace at https://github.com/nodejs/node/issues
    
        at Function.fail (node:internal/assert:17:9)
        at ModuleJobSync.run (node:internal/modules/esm/module_job:430:12)
        at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:647:42)
        at async formattedImport (/Users/rlearney/git/veritable-cloudagent/node_modules/mocha/lib/nodejs/esm-utils.js:9:14)
        at async Object.requireModule [as requireOrImport] (/Users/rlearney/git/veritable-cloudagent/node_modules/mocha/lib/nodejs/esm-utils.js:97:28)
        at async exports.loadFilesAsync (/Users/rlearney/git/veritable-cloudagent/node_modules/mocha/lib/nodejs/esm-utils.js:123:20)
        at async singleRun (/Users/rlearney/git/veritable-cloudagent/node_modules/mocha/lib/cli/run-helpers.js:164:3)
        at async exports.handler (/Users/rlearney/git/veritable-cloudagent/node_modules/mocha/lib/cli/run.js:379:5) {
      code: 'ERR_INTERNAL_ASSERTION'
    }

    NB fixed with NODE_OPTIONS="--no-experimental-strip-types" in all our package.jsons

  5. tbowmo commented on Aug 5, 2025

    @tbowmo
    Author

    What I saw was that suddenly __dirname was not defined. We do not specify type in our package.json files, so the project should fallback to type commons.

    This worked up until nodejs version 22.17, after upgrading to version 22.18 it broke our ci tests.

    Adding the no-experimental-stripe-types option fixed our issue in 22.18.

    I my opinion, this change shouldn't have been added in an 22.x version as a new default setting, as it breaks stuff. It was mentioned in 23.x something though, which is fine.

    (I don't have access to specific failing code right now, will investigate further tomorrow if needed)

  6. simhnna commented on Aug 5, 2025

    @simhnna

    We've also run into this issue while executing tests using mocha --require ts-node/register

  7. himself65 commented on Aug 5, 2025

    @himself65
    Member

    It looks like mocha, ts-node related issue. Not sure how does they implement the loader

  8. marco-ippolito commented on Aug 5, 2025

    @marco-ippolito
    Member

    I'm on PTO, I can look into this next week. Please provide a repro (even something with mocha) I can look into it when I'm back unless someone wants to give it a try

  9. yagrawal-chwy commented on Aug 5, 2025

    @yagrawal-chwy

    You can look at #59366 , launching with NODE_OPTIONS="--no-experimental-strip-types" flag sends Node back to the old loader path; that’s why it cures both the “unexpected feature enabled” problem and the TypeError: undefined.getStatus crash, but I believe these are 2 separate issues - same cause, different effects.

    edit: educated, they're not related

  10. marco-ippolito commented on Aug 5, 2025

    @marco-ippolito
    Member

    You can look at #59366 , launching with NODE_OPTIONS="--no-experimental-strip-types" flag sends Node back to the old loader path; that’s why it cures both the “unexpected feature enabled” problem and the TypeError: undefined.getStatus crash, but I believe these are 2 separate issues - same cause, different effects.

    That doesnt seem related to type stripping though @joyeecheung ideas?

  11. tbowmo commented on Aug 5, 2025

    @tbowmo
    Author

    I'll see if I can make a minimal example with the error in tomorrow.

    This issue is also in the latest 24.5.0, I was struggling for the last couple of weeks upgrading, the this issue with 22. 18 led me to the the --no-experimental flag, which also solves my other problems (this is one gigantius project, that is 7 years old, that I work on. So not always easy to do upgrades)

  12. changed the title [-]node 22.18 suddenly ships with experimental-strip-types enabled[/-] [+]node 22.18 breaks npm pakcage because of `experimental-strip-types` enabled[/+] on Aug 5, 2025
  13. joyeecheung commented on Aug 5, 2025

    @joyeecheung
    Member

    That doesnt seem related to type stripping though @joyeecheung ideas?

    As explained in #59366 (comment) - it might have something to do with the interaction between esbuild-register and the .js handler changes in #58657 (or that it may not be enough to make it transparent enough for esbuild-register)

  14. simhnna commented on Aug 6, 2025

    @simhnna
  15. simhnna commented on Aug 6, 2025

    @simhnna

    And I just tried tsx which isn't affected. So it's something ts-node specific https://github.com/simhnna/node-type-strip-issue/actions/runs/16770273430/job/47483598751

  16. 53 remaining items

  17. jdmarshall commented on Sep 8, 2025

    @jdmarshall

    @alexsch01 iI assume there’s no suitable workaround in third party code?

  18. mantljosh commented on Sep 11, 2025

    @mantljosh

    Here is a reproducer. The same behavior occurs in 22.19. @joyeecheun naively this does seem more related to the loader stuff rather than actually related to the experimental-strip-types flag

    https://github.com/mantljosh/node-22.18-loader-reproducer

  19. chris-lower commented on Sep 25, 2025

    @chris-lower

    My team just wasted a bunch of time debugging this issue. LTS versions should not be including breaking changes like this. It's insane to flip an experimental flag on by default in an LTS version.

  20. cj-christoph-gysin commented on Sep 30, 2025

    @cj-christoph-gysin

    As others mentioned, I encountered issues with node >= 22.18 in combination with mocha. Additionally, we're using the ts-node/esm loader:

    $ mocha --require ts-node/esm
    

    Setting NODE_OPTIONS=--no-experimental-strip-types fixed some of the issues, but caused others. Here's a minimised example to reproduce a bug that was introduced in 22.18.0 when used with --no-experimental-strip-types:

    $ cat mocha-loader-bug.ts
    import { config } from './config.js';
    
    it('test', () => {
      const deployment = config.getRequired<string>('deployment');
      console.log('deployment:', deployment)
    })
    
    $ cat config.ts
    export const config = {
      getRequired: <T>(key: string): T => key as T,
    };
    

    with --no-experimental-strip-types:

    $ NODE_OPTIONS='--loader=ts-node/esm --no-experimental-strip-types' npx mocha mocha-loader-bug.ts
    ...
      1) test:
         ReferenceError: string is not defined
          at Context.<anonymous> (file://mocha-loader-bug.ts:4:41)
          at process.processImmediate (node:internal/timers:485:21)
    

    without --no-experimental-strip-types:

    $ NODE_OPTIONS='--loader=ts-node/esm' npx mocha mocha-loader-bug.ts
    
    deployment: deployment
      ✔ test
    
      1 passing (2ms)
    
    $ node --version
    v22.18.0
    $ npx mocha --version
    11.7.2
    $ npx ts-node --version
    v10.9.2
    
  21. github-actions commented on Apr 29, 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.

  22. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Apr 29, 2026
  23. github-actions commented on May 30, 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