Skip to content

fix: add package.json exports to avoid DEP0151 warning - #6168

Merged
mark-wiemer merged 2 commits into
mochajs:mainfrom
mark-wiemer:mark-wiemer-fix-dep0151-main-exports
Jul 23, 2026
Merged

mark-wiemer merged 2 commits into
mochajs:mainfrom
mark-wiemer:mark-wiemer-fix-dep0151-main-exports

Conversation

@mark-wiemer

@mark-wiemer mark-wiemer commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

PR Checklist

Overview

Adds an exports map that points the package root to the existing ./index.js entry point and keeps a wildcard subpath export so existing deep imports (e.g. mocha/lib/reporters/*) and browser bundle files remain reachable.

Node 22+ emits a [DEP0151] DeprecationWarning when an ES module package is resolved without an explicit "main" or "exports" field. Mocha 12 is now "type": "module", so importing the package root triggered the warning.

exports is the modern alternative to main, supporting advanced features like pattern-matching and conditional exports. main is still supported. Because our project did not have either exports or main before this, we were implicitly exporting everything, and we must continue to do so to avoid a breaking change. Ref https://nodejs.org/api/packages.html#package-entry-points.

In the future, we can restrict what we export for future major versions of Mocha.

mark-wiemer and others added 2 commits July 22, 2026 17:57
Add an explicit exports map so Node stops falling back to
deprecated default index lookups for ESM package resolution.
Keep the wildcard subpath export to preserve existing deep imports
and browser bundle accessibility.

Fixes: mochajs#6147

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.55%. Comparing base (1d2bb2e) to head (48b81e2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6168   +/-   ##
=======================================
  Coverage   82.55%   82.55%           
=======================================
  Files          64       64           
  Lines        4798     4798           
  Branches     1074     1045   -29     
=======================================
  Hits         3961     3961           
  Misses        837      837           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mark-wiemer mark-wiemer mentioned this pull request Jul 23, 2026
3 tasks done

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exports is the modern alternative to main

This - I'm in favor of preferring the new modern thing.

@mark-wiemer
mark-wiemer merged commit 3031567 into mochajs:main Jul 23, 2026
228 of 229 checks passed
@mark-wiemer
mark-wiemer deleted the mark-wiemer-fix-dep0151-main-exports branch July 23, 2026 14:15
@mark-wiemer mark-wiemer mentioned this pull request Jul 24, 2026
11 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug: [DEP0151] No "main" or "exports" field defined in the package.json

2 participants