Skip to content

fix: unbreak yarn test:unit (jest 30.5.1 + cross-platform native bindings) - #2102

Merged
martin-helmich merged 2 commits into
masterfrom
fix/jest-esm-package-imports
Sep 3, 2026
Merged

fix: unbreak yarn test:unit (jest 30.5.1 + cross-platform native bindings)#2102
martin-helmich merged 2 commits into
masterfrom
fix/jest-esm-package-imports

Conversation

@martin-helmich

Copy link
Copy Markdown
Member

yarn test:unit currently fails. Two independent causes, one commit each.

1. ReferenceError: Cannot access 'supportsColor' before initialization

jest-runtime@30.5.0 (came in with #2094) added splitQueryAndFragment(), which strips URL query/fragment suffixes from import specifiers — but it scans from index 0. A Node package-imports specifier such as chalk's #supports-color is therefore read as a bare fragment, leaving an empty specifier that resolves back to the importing module itself. chalk ends up importing its own default export and dies in the temporal dead zone:

ReferenceError: Cannot access 'supportsColor' before initialization
  at node_modules/chalk/source/index.js:8:52

Every suite that reaches chalk or ink was affected: Table, DeleteBaseCommand, config_builder, app/uninstall.

Upstream fixed it in 30.5.1 by starting the scan after a leading #:

const scanFrom = specifier.startsWith('#') ? 1 : 0;
const hashIndex = specifier.indexOf('#', scanFrom);

So this is just yarn up jest @jest/globals. Ranges are bumped to ^30.5.1 so the fix cannot be silently lost by a downgrade.

2. Module ts-jest in the transform option was not found

jest-resolve@30 resolves through unrs-resolver, a native module whose platform binding is selected at install time. An install performed on macOS leaves node_modules without a Linux binding; on Linux the binding fails to load, the resolver silently returns null, and jest surfaces it as a missing transformer. This affects Linux CI and dev containers that share a node_modules/cache produced on a macOS workstation.

Declaring supportedArchitectures in .yarnrc.yml makes a single install cover darwin + linux on arm64 + x64, for unrs-resolver, esbuild and @parcel/watcher alike. Cost is roughly 7 MB of extra binaries in the committed Yarn cache — happy to drop this commit if that trade isn't wanted.

Verification

  • yarn test:unit — 20 suites, 153 tests, 0 failures (was: 4 suites failing)
  • yarn compile — clean
  • yarn lint — clean

🤖 Generated with Claude Code

martin-helmich and others added 2 commits September 3, 2026 08:44
jest-runtime 30.5.0 added splitQueryAndFragment(), which strips URL
query/fragment suffixes from import specifiers but scans from index 0.
A Node package-imports specifier such as chalk's "#supports-color" was
therefore read as a bare fragment, leaving an empty specifier that
resolved back to the importing module itself. chalk then imported its
own default export and died in the temporal dead zone:

    ReferenceError: Cannot access 'supportsColor' before initialization
      at node_modules/chalk/source/index.js:8:52

That broke every suite reaching chalk or ink: Table, DeleteBaseCommand,
config_builder and app/uninstall.

Upstream fixed it in 30.5.1 by starting the scan after a leading "#".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
jest-resolve 30 resolves through unrs-resolver, a native module whose
binding is picked at install time. An install performed on macOS leaves
node_modules without a Linux binding, so jest-resolve silently returns
null on Linux and jest reports it as a missing transformer:

    Module ts-jest in the transform option was not found.

This hits Linux CI and dev containers that share a node_modules or cache
produced on a macOS workstation. Declaring supportedArchitectures makes
one install cover darwin and linux on arm64 and x64, for unrs-resolver,
esbuild and @parcel/watcher alike.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@gandie gandie 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.

tested locally, works.

much better fix. although i strongly dislike the fact that testing libs themselves break in such fashion. i went wrong with trusting those libs to just work out of the box, looking for errors rather on the consuming side of things. a failing testing lib during imports is a new level of chaos to manage for me 😆

LGTM!

@martin-helmich
martin-helmich merged commit 54fc821 into master Sep 3, 2026
11 checks passed
@martin-helmich
martin-helmich deleted the fix/jest-esm-package-imports branch September 3, 2026 08:09
mittwald-machine added a commit that referenced this pull request Sep 3, 2026
## [1.24.1](v1.24.0...v1.24.1) (2026-09-03)

### Bug Fixes

* **release:** switch to qwen3.8 for relase announcement ([#2100](#2100)) ([62c6f95](62c6f95))
* unbreak yarn test:unit (jest 30.5.1 + cross-platform native bindings) ([#2102](#2102)) ([54fc821](54fc821)), closes [#2094](#2094)
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.

2 participants