Thanks to visit codestin.com
Credit goes to github.com

Skip to content

πŸ› Bug: Combining mocha, ESM, tsx and imports of typescript interfaces results in ERR_INTERNAL_ASSERTIONΒ #5452

@fvictorio

Description

@fvictorio

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

Combining mocha with tsx and ESM, and importing an interface without using import type should work.

Actual

Mocha throws an error when that combination of features is used.

Minimal, Reproducible Example

  1. Clone https://github.com/fvictorio/mocha-5452
  2. Run npm install && npx mocha test.ts. You'll get an error like 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 πŸ› Bug: Unhelpful error message when a default import is made from a module without a default exportΒ #5411, which was already fixed. But using the 11.7.2 version of mocha still results in an error, just with a better message: Exception during run: SyntaxError: The requested module './foo.js' does not provide an export named 'Foo'.

If I change import { Foo } to import type { Foo }, things work.

Running the same file directly by doing node --tsx/esm test.ts works fine, which is what makes me think that this is a mocha issue.

Versions

Using the version in main:

$ npx mocha --version
11.7.1
$ /node_modules/.bin/mocha --version
11.7.1
$ node --version
v24.7.0

Additional Info

No response

Metadata

Metadata

Assignees

Labels

area: integrationsrelated to working with 3rd party software (e.g., babel, typescript)status: wontfixtypically a feature which won't be added, or a "bug" which is actually intended behaviortype: buga defect, confirmed by a maintainer

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions