fix(testing): convert executor-based jest.config.ts and preserve type-only imports#35286
Merged
FrozenPandaz merged 1 commit intomasterfrom Apr 27, 2026
Merged
fix(testing): convert executor-based jest.config.ts and preserve type-only imports#35286FrozenPandaz merged 1 commit intomasterfrom
FrozenPandaz merged 1 commit intomasterfrom
Conversation
…-only imports Runs convert-jest-config-to-cjs for every jest.config.ts with a CJS-compatible package.json type, not just plugin-registered ones, so executor-based workspaces stop crashing on native type-stripping loaders (readConfig). Keeps `import type` declarations and splits inline `type` specifiers into a type-only import plus a require so editor/tsc type safety is retained.
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
|
View your CI Pipeline Execution ↗ for commit 599bbb4
☁️ Nx Cloud last updated this comment at |
FrozenPandaz
approved these changes
Apr 27, 2026
ShwethaSundar
pushed a commit
to ShwethaSundar/nx
that referenced
this pull request
Apr 27, 2026
…-only imports (nrwl#35286) ## Current Behavior `nx migrate --run-migrations` crashes on workspaces that use the `@nx/jest:jest` executor (via `targetDefaults`) instead of `@nx/jest/plugin`: ``` NX Failed to run replace-removed-matcher-aliases-v22-3 from @nx/jest. This workspace is NOT up to date! NX Jest: Failed to parse the TypeScript config file .../libs/.../jest.config.ts ReferenceError: __dirname is not defined in ES module scope ``` The `convert-jest-config-to-cjs` migration (update-22-2-0) is gated on `@nx/jest/plugin` being registered in `nx.json`, so executor-based workspaces skip it entirely. Their `jest.config.ts` files (often a mix of ESM syntax and CJS globals like `__dirname`) never get converted. The later `replace-removed-matcher-aliases-v22-3` migration then calls `jest-config.readConfig` on every `jest.config.ts`, which on Node 22+/24+ with native type-stripping reparses the file as ESM and crashes. Separately, the conversion logic also didn't handle `import type` declarations — it rewrote them to `const { X } = require('mod')`, which unnecessarily pulls the module at runtime and drops type references the IDE/tsc relied on. For types-only specifiers, it could even crash at runtime. ## Expected Behavior `convert-jest-config-to-cjs` runs for every `jest.config.ts` whose project is CommonJS (plugin registration is no longer required), so executor-based setups are covered. The `type: module` guard still skips ESM projects. Type-only imports are preserved: - `import type { Config } from 'jest'` — left untouched (Node's type-stripping erases it, so it doesn't force ESM parsing at runtime). - `import { type Foo, bar } from 'mod'` — split into `import type { Foo } from 'mod'` plus `const { bar } = require('mod')`. - Renames (`import { type Foo as JestFoo, run } from 'mod'`) preserved. ## Related Issue(s) Fixes nrwl#34593
FrozenPandaz
pushed a commit
that referenced
this pull request
Apr 28, 2026
…-only imports (#35286) ## Current Behavior `nx migrate --run-migrations` crashes on workspaces that use the `@nx/jest:jest` executor (via `targetDefaults`) instead of `@nx/jest/plugin`: ``` NX Failed to run replace-removed-matcher-aliases-v22-3 from @nx/jest. This workspace is NOT up to date! NX Jest: Failed to parse the TypeScript config file .../libs/.../jest.config.ts ReferenceError: __dirname is not defined in ES module scope ``` The `convert-jest-config-to-cjs` migration (update-22-2-0) is gated on `@nx/jest/plugin` being registered in `nx.json`, so executor-based workspaces skip it entirely. Their `jest.config.ts` files (often a mix of ESM syntax and CJS globals like `__dirname`) never get converted. The later `replace-removed-matcher-aliases-v22-3` migration then calls `jest-config.readConfig` on every `jest.config.ts`, which on Node 22+/24+ with native type-stripping reparses the file as ESM and crashes. Separately, the conversion logic also didn't handle `import type` declarations — it rewrote them to `const { X } = require('mod')`, which unnecessarily pulls the module at runtime and drops type references the IDE/tsc relied on. For types-only specifiers, it could even crash at runtime. ## Expected Behavior `convert-jest-config-to-cjs` runs for every `jest.config.ts` whose project is CommonJS (plugin registration is no longer required), so executor-based setups are covered. The `type: module` guard still skips ESM projects. Type-only imports are preserved: - `import type { Config } from 'jest'` — left untouched (Node's type-stripping erases it, so it doesn't force ESM parsing at runtime). - `import { type Foo, bar } from 'mod'` — split into `import type { Foo } from 'mod'` plus `const { bar } = require('mod')`. - Renames (`import { type Foo as JestFoo, run } from 'mod'`) preserved. ## Related Issue(s) Fixes #34593
Contributor
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Current Behavior
nx migrate --run-migrationscrashes on workspaces that use the@nx/jest:jestexecutor (viatargetDefaults) instead of@nx/jest/plugin:The
convert-jest-config-to-cjsmigration (update-22-2-0) is gated on@nx/jest/pluginbeing registered innx.json, so executor-based workspaces skip it entirely. Theirjest.config.tsfiles (often a mix of ESM syntax and CJS globals like__dirname) never get converted. The laterreplace-removed-matcher-aliases-v22-3migration then callsjest-config.readConfigon everyjest.config.ts, which on Node 22+/24+ with native type-stripping reparses the file as ESM and crashes.Separately, the conversion logic also didn't handle
import typedeclarations — it rewrote them toconst { X } = require('mod'), which unnecessarily pulls the module at runtime and drops type references the IDE/tsc relied on. For types-only specifiers, it could even crash at runtime.Expected Behavior
convert-jest-config-to-cjsruns for everyjest.config.tswhose project is CommonJS (plugin registration is no longer required), so executor-based setups are covered. Thetype: moduleguard still skips ESM projects.Type-only imports are preserved:
import type { Config } from 'jest'— left untouched (Node's type-stripping erases it, so it doesn't force ESM parsing at runtime).import { type Foo, bar } from 'mod'— split intoimport type { Foo } from 'mod'plusconst { bar } = require('mod').import { type Foo as JestFoo, run } from 'mod') preserved.Related Issue(s)
Fixes #34593