Skip to content

fix(vitest): use esm config files and import.meta.dirname - #36605

Merged
jaysoo merged 8 commits into
masterfrom
NXC-4772
Aug 10, 2026
Merged

fix(vitest): use esm config files and import.meta.dirname#36605
jaysoo merged 8 commits into
masterfrom
NXC-4772

Conversation

@jaysoo

@jaysoo jaysoo commented Aug 7, 2026

Copy link
Copy Markdown
Member

Current Behavior

Vite 8.2 warns that Nx-generated configs use features configLoader: 'native' cannot support: __dirname in vitest.config.mts, and ESM syntax in a CommonJS-loaded root vitest.config.ts. @nx/vite fixed this in 22.1.1; @nx/vitest forked before that and kept __dirname.

Expected Behavior

No warning. __dirname becomes import.meta.dirname, the root aggregator and the vitest 3 workspace file are written as .mts, and a migration backfills __dirname in existing .mts/.mjs configs.

Related Issue(s)

NXC-4772


View Polygraph session ↗

## Current Behavior
Vite 8.2 warns that Nx-generated configs use features `configLoader: 'native'`
cannot support:

- `__dirname` in `vitest.config.mts`
- ESM syntax in a CommonJS-loaded root `vitest.config.ts`

`@nx/vite` fixed this in 22.1.1. `@nx/vitest` forked before that and kept
`__dirname`.

## Expected Behavior
No warning.

- `__dirname` -> `import.meta.dirname` (3 sites, matching `@nx/vite`)
- root aggregator written as `vitest.config.mts`
- vitest 3 `vitest.workspace.ts` -> `.mts`
- nuxt emits `.mts` unless the workspace is on eslintrc, where legacy
  `@nuxt/eslint-config` cannot parse it
- migration backfills `__dirname` in existing `.mts`/`.mjs` configs

## Related Issue(s)
NXC-4772
@netlify

netlify Bot commented Aug 7, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 5e60402
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6a7a061467d55700080a49d5
😎 Deploy Preview https://deploy-preview-36605--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 7, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 5e60402
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6a7a0614902c450008eeb36a
😎 Deploy Preview https://deploy-preview-36605--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud

nx-cloud Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit f04b875

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 7m 47s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 4s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 55s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 18s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 5s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-10 17:23:12 UTC

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud Bot and others added 3 commits August 7, 2026 20:49
## Current Behavior
The migration rewrote `__dirname` anywhere it appeared as an identifier,
including positions where `import.meta.dirname` is not legal syntax:

- `const { __dirname: dir } = opts`
- `import { __dirname as dir } from './paths.mjs'`
- `export { __dirname } from './paths.mjs'`

Each produced an unparseable config.

## Expected Behavior
Rename keys, aliased import specifiers, and re-exports are left alone. Real
references in the same file are still rewritten.

## Related Issue(s)
NXC-4772
nx-cloud[bot]

This comment was marked as outdated.

jaysoo and others added 2 commits August 10, 2026 08:47
… storybook

## Current Behavior
Three generators write their vite config from a standalone template under
`files/`, bypassing `createOrEditViteConfig`, so `useEsmExtension` never
applied and they emitted `vite.config.ts`. ESM source in a `.ts` config loaded
as CommonJS trips Vite's `configLoader: 'native'` warning.

## Expected Behavior
All three emit `vite.config.mts`:

- `@nx/react:consumer`
- `@nx/react:provider`
- `@nx/remix:storybook-configuration`

The remix generator still skips generation when a `.ts` config already exists.

## Related Issue(s)
NXC-4772
nx-cloud[bot]

This comment was marked as outdated.

@jaysoo
jaysoo marked this pull request as ready for review August 10, 2026 13:59
@jaysoo
jaysoo requested a review from a team as a code owner August 10, 2026 13:59
@jaysoo
jaysoo requested a review from leosvelperez August 10, 2026 13:59
jaysoo and others added 2 commits August 10, 2026 12:12
## Current Behavior
Docs print the pre-rename filenames, so step one of a tutorial does not match
what the reader sees:

- provider/consumer trees show `vite.config.ts`
- react, angular and typescript-packages workspace trees show a root
  `vitest.config.ts`

The migration doc also read as though the CommonJS warning was fully handled.

## Expected Behavior
Trees show `.mts`. The migration doc states that existing `.ts` configs are
left alone by design, so that warning stays until the user renames the file or
sets `"type": "module"`, and notes the one generated `.ts` case (nuxt on
eslintrc).

Also from review: `classify` now excludes every parent name position rather
than enumerating node kinds, so class fields, accessors and enum members are no
longer rewritten into invalid syntax; configs with parse errors are skipped;
the workspace-file extension guards match the inference plugin's list.

## Related Issue(s)
NXC-4772

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nx Cloud has identified a flaky task in your failed CI:

🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.

Nx Cloud View detailed reasoning in Nx Cloud ↗

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.


🎓 Learn more about Self-Healing CI on nx.dev

@jaysoo
jaysoo merged commit 23fb6de into master Aug 10, 2026
18 checks passed
@jaysoo
jaysoo deleted the NXC-4772 branch August 10, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants