Repository navigation
fix(cjs): fail clearly on Node without require(esm) - #69
Merged
Merged
Conversation
src/cjs-shim.cjs loaded dist/index.mjs via createRequire(__filename),
but a .cjs file already has a plain require() available — createRequire
is unnecessary and breaks static-require detection in bundlers like
esbuild/webpack. Switched to a plain require("./index.mjs").
On Node.js versions without require(esm) (before 20.19 / 22.12), that
plain require() would fail with a bare, confusing ERR_REQUIRE_ESM.
Check process.features.require_module up front and throw a clear
message pointing at import() instead.
tests/cjs: node:test checks run by npm test/coverage after Vitest:
require() returns the same named exports as import, and the version
check fires when require(esm) is off.
Shinrai
approved these changes
Oct 3, 2026
cldmv-bot Bot
added a commit
that referenced
this pull request
Oct 4, 2026
# vitest-runner v1.5.3 Changelog
**Release Date**: October 2026
**Release Type**: Patch
**Branch**: `release/1.5.3`
---
## Overview
This release changes how `dist/index.cjs` loads the ES module build. The CommonJS entry no longer goes through `createRequire`, which kept bundlers from seeing the dependency, and it now fails with a clear, actionable error on a Node.js version that cannot `require()` an ES module. New `node:test` checks run the built CommonJS entry point on every test and coverage run.
The ES module build, the CLI and the `run()` API are unchanged, and on Node.js versions with `require(esm)` (20.19+ and 22.12+), `require("@cldmv/vitest-runner")` returns the same named exports as before.
It also raises `engines.node` to `>=22.12.0` ([#73](#73)). The old `>=20.19.0` floor was never true: the runtime dependency `chalk` 6 needs Node.js 22, the current `vitest` 5 peer needs `^22.12.0`, and CI only ever tested 22.12 and later.
---
## 💥 Breaking Changes
### Node.js 20 is no longer supported ([#73](#73), fixes [#72](#72))
`engines.node` moves from `>=20.19.0` to `>=22.12.0`, despite this being a patch release. In practice Node.js 20 already stopped working cleanly in v1.5.2: `chalk` 6.0.1 declares Node.js 22 or later, so Node.js 20 installs printed an `EBADENGINE` warning and failed outright under `engine-strict`, and `vitest` 5 does not install on Node.js 20 at all. The floor now says what the package actually needs.
## 🐛 Bug Fixes
### The CommonJS entry uses a plain `require()` (#69)
`src/cjs-shim.cjs`, which the build copies verbatim to `dist/index.cjs`, loaded `./index.mjs` through `createRequire(__filename)`. A `.cjs` file already has `require`, so `createRequire` added nothing, and it hid the dependency from bundlers such as esbuild and webpack, which detect dependencies from static `require("…")` calls. The shim now calls `require("./index.mjs")` directly and exports its result.
### `require()` fails clearly on Node.js without `require(esm)` (#69)
On a Node.js version without synchronous `require(esm)` (before 20.19 on the 20.x line, or before 22.12), the shim's `require()` threw a generic `ERR_REQUIRE_ESM` that pointed at the package's internals. The shim now checks `process.features.require_module` first and, when it is missing, throws an error with the same `ERR_REQUIRE_ESM` code and a message naming the package, the required versions and the running version:
```text
@cldmv/vitest-runner: require() needs Node.js ^20.19.0 or >=22.12.0 (this is v20.18.0). On older Node.js, load the package with import() instead.
```
Code that catches `ERR_REQUIRE_ESM` by `code` keeps working.
## 🧪 Tests
- New `tests/cjs/entry.test.cjs`, run with `node --test` by a new `test:cjs` script after a fresh `npm run build`. It checks that `require()` of the built package returns the same named exports as `import`, and that the version check throws the new error when `require(esm)` is unavailable.
- `npm test`, `npm run test:coverage` and `npm run ci:coverage` now run `test:cjs` after Vitest, so CI exercises the published CommonJS entry point.
## 📄 License
- The package is relicensed from MIT to [Apache-2.0](https://github.com/CLDMV/vitest-runner/blob/master/LICENSE): `LICENSE` now carries the Apache License 2.0 text and `package.json` declares `"license": "Apache-2.0"`.
## 📚 Documentation
- **NEW:** [docs/changelog/v1/v1.5.3.md](./v1.5.3.md): this changelog.
- **NEW:** changelog files for every earlier release that shipped without one: [v1.0.0](./v1.0.0.md), [v1.0.1](./v1.0.1.md), [v1.0.2](./v1.0.2.md), [v1.0.3](./v1.0.3.md), [v1.1.0](./v1.1.0.md), [v1.2.0](./v1.2.0.md), [v1.3.0](./v1.3.0.md), [v1.3.1](./v1.3.1.md), [v1.3.2](./v1.3.2.md), [v1.3.3](./v1.3.3.md) and [v1.5.2](./v1.5.2.md).
- README restructured to the CLDMV layout (badges, **What's New**, Key Features, Installation with Node.js requirements, Quick Start, then the existing CLI, API and coverage reference). The install commands now use the scoped package name `@cldmv/vitest-runner`, and the Node.js requirement matches `engines.node`.
## 🔧 Dependencies
_No dependency updates._
---
## Upgrade notes
- **Node.js 22.12 or later is required.** On Node.js 20, stay on v1.5.1 (the last release before `chalk` 6), or upgrade Node.js. Everyone already on Node.js 22.12+ gets a drop-in update from [v1.5.2](./v1.5.2.md).
- On a Node.js version without `require(esm)`, `require()` now fails with a clearer message and the same `ERR_REQUIRE_ESM` code.
<details>
<summary>👥 Contributors</summary>
- @Shinrai
</details>
---
<!-- coverage-start -->

| Metric | Coverage |
|--------|----------|
| Statements | 99.4% |
| Branches | 99.6% |
| Functions | 100.0% |
| Lines | 99.3% |
*Avg: **99.5%** · `13bf37c` · Node lts/**
<!-- coverage-end -->
<!-- co-authors -->
Co-authored-by: Shinrai <Shinrai@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 What's Changed
💥 Breaking Changes
No breaking changes
✨ Features
No new features
🐛 Bug Fixes
📦 Dependencies
No dependency updates
🔧 Other Changes
No other changes
👥 Contributors