Skip to content

fix(js): remove redundant vite.config.ts generation for vitest projects#34603

Merged
jaysoo merged 1 commit intomasterfrom
issue-34399
Feb 25, 2026
Merged

fix(js): remove redundant vite.config.ts generation for vitest projects#34603
jaysoo merged 1 commit intomasterfrom
issue-34399

Conversation

@jaysoo
Copy link
Member

@jaysoo jaysoo commented Feb 25, 2026

Current Behavior

When generating a library with vitest as the test runner and a non-vite bundler (e.g. tsc), the js library generator creates two config files:

  • vitest.config.mts (from the vitest configurationGenerator) with root: __dirname
  • vite.config.ts (from a second createOrEditViteConfig call) with root: import.meta.dirname

The redundant vite.config.ts uses ESM-only import.meta.dirname syntax, which causes TS1470 when the project targets CommonJS output:

vite.config.ts:5:9 - error TS1470: The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.

5   root: import.meta.dirname,
          ~~~~~~~~~~~

Expected Behavior

Only vitest.config.mts should be generated. The vitest configurationGenerator already handles creating the correct config file with root: __dirname. The second createOrEditViteConfig call from @nx/vite was redundant and produced the conflicting file.

Related Issue(s)

Fixes #34399

@jaysoo jaysoo requested a review from a team as a code owner February 25, 2026 15:53
@jaysoo jaysoo requested a review from FrozenPandaz February 25, 2026 15:53
@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 52d6c01
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/699f2d44b446df0007754eb7
😎 Deploy Preview https://deploy-preview-34603--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
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 52d6c01
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/699f2d44875b3a0008fa6f31
😎 Deploy Preview https://deploy-preview-34603--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
Copy link
Contributor

nx-cloud bot commented Feb 25, 2026

View your CI Pipeline Execution ↗ for commit 52d6c01

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 5m 29s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 26s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-25 17:21:24 UTC

Copy link
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

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

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud has identified a possible root cause for your failed CI:

We've classified these failures as environment_state because the failing plugin:test task is in a project not touched by this PR (which only modifies the js package), and the error indicates a Jest infrastructure issue with native bindings rather than application logic. The PR's changes to remove redundant vite.config.ts generation have no logical connection to plugin package tests or Jest's native binding loading.

No code changes were suggested for this issue.

Trigger a rerun:

Rerun CI

Nx Cloud View detailed reasoning on 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

## Current Behavior

When generating a library with vitest as the test runner and a non-vite
bundler (e.g. tsc), the js library generator creates two config files:
- `vitest.config.mts` (from the vitest configurationGenerator) with `root: __dirname`
- `vite.config.ts` (from a second createOrEditViteConfig call) with `root: import.meta.dirname`

The redundant `vite.config.ts` uses ESM-only `import.meta.dirname` syntax,
which causes TS1470 when the project targets CommonJS output.

## Expected Behavior

Only `vitest.config.mts` should be generated since the vitest
configurationGenerator already handles creating the correct config file.

## Related Issue(s)

Fixes #34399
@jaysoo jaysoo requested a review from a team as a code owner February 25, 2026 17:11
@jaysoo jaysoo merged commit 1e3f8e0 into master Feb 25, 2026
24 checks passed
@jaysoo jaysoo deleted the issue-34399 branch February 25, 2026 17:27
FrozenPandaz pushed a commit that referenced this pull request Feb 26, 2026
…ts (#34603)

## Current Behavior

When generating a library with vitest as the test runner and a non-vite
bundler (e.g. `tsc`), the js library generator creates two config files:
- `vitest.config.mts` (from the vitest `configurationGenerator`) with
`root: __dirname`
- `vite.config.ts` (from a second `createOrEditViteConfig` call) with
`root: import.meta.dirname`

The redundant `vite.config.ts` uses ESM-only `import.meta.dirname`
syntax, which causes TS1470 when the project targets CommonJS output:

```
vite.config.ts:5:9 - error TS1470: The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.

5   root: import.meta.dirname,
          ~~~~~~~~~~~
```

## Expected Behavior

Only `vitest.config.mts` should be generated. The vitest
`configurationGenerator` already handles creating the correct config
file with `root: __dirname`. The second `createOrEditViteConfig` call
from `@nx/vite` was redundant and produced the conflicting file.

## Related Issue(s)

Fixes #34399

(cherry picked from commit 1e3f8e0)
FrozenPandaz pushed a commit that referenced this pull request Feb 26, 2026
…ts (#34603)

## Current Behavior

When generating a library with vitest as the test runner and a non-vite
bundler (e.g. `tsc`), the js library generator creates two config files:
- `vitest.config.mts` (from the vitest `configurationGenerator`) with
`root: __dirname`
- `vite.config.ts` (from a second `createOrEditViteConfig` call) with
`root: import.meta.dirname`

The redundant `vite.config.ts` uses ESM-only `import.meta.dirname`
syntax, which causes TS1470 when the project targets CommonJS output:

```
vite.config.ts:5:9 - error TS1470: The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.

5   root: import.meta.dirname,
          ~~~~~~~~~~~
```

## Expected Behavior

Only `vitest.config.mts` should be generated. The vitest
`configurationGenerator` already handles creating the correct config
file with `root: __dirname`. The second `createOrEditViteConfig` call
from `@nx/vite` was redundant and produced the conflicting file.

## Related Issue(s)

Fixes #34399

(cherry picked from commit 1e3f8e0)
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@nx/plugin generate invalid vite.config.ts file

2 participants