Skip to content

🐛 Bug: Unhelpful error message when a default import is made from a module without a default export #5411

@martinslota

Description

@martinslota

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

When a default import is made from a module without a default export, I expect an error message such as:

SyntaxError: The requested module './index.js' does not provide an export named 'default'

This is also what Mocha until version 11.7.0 gives.

Actual

In Mocha version 11.7.1, I get the following error message instead:

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

@papandreou bisected the commits and found out that the issue was introduced in #5384.

Minimal, Reproducible Example

https://github.com/martinslota/mocha-default-import-error

Versions

11.7.1

Additional Info

No response

Metadata

Metadata

Assignees

Labels

semver-patchimplementation requires increase of "patch" version number; "bug fixes"status: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions