Skip to content

Commit d41d166

Browse files
os-litantclaude
andauthored
fix(metadata-core, service-cluster): make the ./testing subpaths ESM-only (#13001)
Both packages published ./testing as a dual entry point, but the subpath re-exports vitest and vitest refuses to be loaded from CommonJS by design, so the require condition could never resolve to working code. Drop the condition and delete the two now-stale entries from the shrink-only scripts/dual-build-cjs-loads.baseline.json ledger in the same change. Claude-Session: https://claude.ai/code/session_01UjujZN219uFzBhSYfMykCd Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2852acc commit d41d166

4 files changed

Lines changed: 62 additions & 14 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
"@objectstack/metadata-core": minor
3+
"@objectstack/service-cluster": minor
4+
---
5+
6+
fix: the `./testing` subpaths are ESM-only — they no longer advertise a `require` condition vitest refuses to serve (#12985)
7+
8+
Both packages published their test-harness subpath as a dual entry point:
9+
10+
```jsonc
11+
// FROM — @objectstack/metadata-core and @objectstack/service-cluster
12+
"./testing": {
13+
"types": "./dist/testing.d.ts",
14+
"import": "./dist/testing.js",
15+
"require": "./dist/testing.cjs"
16+
}
17+
18+
// TO
19+
"./testing": {
20+
"types": "./dist/testing.d.ts",
21+
"import": "./dist/testing.js"
22+
}
23+
```
24+
25+
The `require` half was a promise neither package could keep. Both subpaths
26+
re-export `vitest`, and vitest **refuses** to be loaded from CommonJS by
27+
design — its CJS entry is a single `throw`:
28+
29+
```
30+
node -e "require('@objectstack/metadata-core/testing')"
31+
Error: Vitest cannot be imported in a CommonJS module using require(). Please use "import" instead.
32+
```
33+
34+
The emitted bytes parse; the load fails inside vitest's own entry, for every
35+
consumer and every code path. So the condition could never resolve to working
36+
code, on any release, since it was first declared. It is removed rather than
37+
repaired because the failure is not ours to fix: a test harness has no business
38+
advertising a `require` condition when the test runner it re-exports does not
39+
serve one.
40+
41+
**Nothing that worked stops working**, and that is why this is not filed as a
42+
breaking removal. A CJS consumer that resolved through the old condition got a
43+
hard `Error` at load; it now gets a resolution error from node instead — a
44+
different message for the same non-working call, and an earlier and clearer
45+
one. The `import` condition, the types and the runtime API are untouched, and
46+
every in-repo consumer already reaches these subpaths through `import`
47+
(`@objectstack/metadata-fs`, `@objectstack/metadata-protocol`,
48+
`@objectstack/rest`, `@objectstack/runtime`, `@objectstack/service-cluster-redis`).
49+
50+
**If you did spell it as `require`**`require('@objectstack/metadata-core/testing')`
51+
or `require('@objectstack/service-cluster/testing')` — switch the call to
52+
`await import('@objectstack/metadata-core/testing')`, or move the calling
53+
module to ESM. That is the same change the old condition already forced on
54+
you, one error message earlier.
55+
56+
`dist/testing.cjs` is still emitted (both packages build every entry in both
57+
formats) and still parsed by `pnpm check:dual-build-cjs-loads`; it is simply no
58+
longer reachable through the manifest. Removing it from the build is a
59+
tsup-config change with its own risks and is not folded in here.

packages/metadata-core/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
},
1515
"./testing": {
1616
"types": "./dist/testing.d.ts",
17-
"import": "./dist/testing.js",
18-
"require": "./dist/testing.cjs"
17+
"import": "./dist/testing.js"
1918
}
2019
},
2120
"files": [

packages/services/service-cluster/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
},
1515
"./testing": {
1616
"types": "./dist/testing.d.ts",
17-
"import": "./dist/testing.js",
18-
"require": "./dist/testing.cjs"
17+
"import": "./dist/testing.js"
1918
}
2019
},
2120
"scripts": {
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
{
22
"$comment": "Shrink-only, hand-edited. Published `require` entry points that legitimately cannot be require()d, each with the reason. Read by scripts/check-dual-build-cjs-loads.mjs. An entry that starts loading must be DELETED in the same PR that fixes it — the gate reds on a stale exemption. ⛔ A parse failure (SyntaxError in our own emitted bytes) is NEVER ledgerable: the gate ignores an entry here for that class on purpose, because a parse failure is always a fact about what we emitted, never about a dependency. Its steady state is NOT empty — read the reasons, never the count.",
3-
"entries": {
4-
"@objectstack/metadata-core#./testing": {
5-
"reason": "The subpath re-exports vitest, and vitest REFUSES to be loaded from CommonJS by design ('Vitest cannot be imported in a CommonJS module using require(). Please use \"import\" instead.'). The bytes parse; the load fails inside vitest's own entry. Pre-existing and independent of #12971 — the same `require` condition is present at b489d3c725e8, before the import.meta line landed. The real repair is at the manifest (a test-harness subpath has no business advertising a `require` condition), which is a published-exports change and belongs to its own card.",
6-
"diagnostic": "Error: Vitest cannot be imported in a CommonJS module using require()."
7-
},
8-
"@objectstack/service-cluster#./testing": {
9-
"reason": "Same shape as @objectstack/metadata-core#./testing — a vitest-backed test-harness subpath that declares a `require` condition vitest itself refuses to serve. Bytes parse, load fails inside vitest. Repair is the same manifest-level one and belongs to the same card.",
10-
"diagnostic": "Error: Vitest cannot be imported in a CommonJS module using require()."
11-
}
12-
}
3+
"entries": {}
134
}

0 commit comments

Comments
 (0)