Skip to content

fix(config): patch ssr.resolve.conditions to remove import#1732

Merged
danielroe merged 2 commits into
nuxt:mainfrom
yamachi4416:patch-ssr-resolve-conditions
Jul 14, 2026
Merged

fix(config): patch ssr.resolve.conditions to remove import#1732
danielroe merged 2 commits into
nuxt:mainfrom
yamachi4416:patch-ssr-resolve-conditions

Conversation

@yamachi4416

@yamachi4416 yamachi4416 commented Jul 4, 2026

Copy link
Copy Markdown
Member

🔗 Linked issue

resolves #1635

📚 Description

This was an issue in test-utils.
config.environments.ssr.resolve.conditions seems to be applied to config.ssr.resolve.conditions for backward compatibility. If 'import' is included in config.ssr.resolve.conditions, Vitest fails to resolve the pg module in test run.

Reproduction

https://stackblitz.com/edit/nuxt-test-utils-pull-1732-after?file=package.json

@yamachi4416 yamachi4416 changed the title fix(config): add patch ssr.resolve.conditions fix(config): add patch environments.ssr.resolve.conditions Jul 4, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/test-utils@1732
npm i https://pkg.pr.new/vitest-environment-nuxt@1732

commit: 9f736ee

@yamachi4416
yamachi4416 marked this pull request as ready for review July 4, 2026 11:13
@yamachi4416
yamachi4416 requested a review from danielroe as a code owner July 4, 2026 11:13
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This change updates the nuxt:test-utils:browser-conditions Vite plugin in src/config.ts to add a configResolved hook. When SSR-specific resolve conditions are present, the hook filters config.ssr.resolve.conditions to remove the 'import' condition.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Changes

File Summary
src/config.ts Added configResolved logic to filter 'import' from SSR resolve conditions.

Related issues: #1635 — Import of postgres ("pg") breaks when using nuxt test-utils with vitest >= 4.1.0.

Suggested labels: bug, vitest

Suggested reviewers: danielroe

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The change removes 'import' from SSR resolve conditions, matching the reported pg resolution failure in #1635.
Out of Scope Changes check ✅ Passed The patch is narrowly focused on SSR resolve conditions and introduces no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately reflects the config fix that removes import from SSR resolve conditions.
Description check ✅ Passed The description matches the test-utils/Vitest resolution issue and the pg import failure this change addresses.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/config.ts (1)

219-228: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider returning a partial config instead of mutating config directly.

Vite's plugin API docs recommend returning a partial config object (deep-merged automatically) and reserve direct mutation for cases where merging can't achieve the desired result: It can return a partial config object that will be deeply merged into existing config, or directly mutate the config (if the default merging cannot achieve the desired result). The official configEnvironment example for this exact use case also returns a partial config: configEnvironment(name: string, options: EnvironmentOptions) { // add "workerd" condition to the rsc environment if (name === 'rsc') { return { resolve: { conditions: ['workerd'], }, } } }

♻️ Align with documented pattern
         {
           // https://github.com/nuxt/test-utils/issues/1635
           name: 'nuxt:test-utils:patch-ssr-conditions',
           enforce: 'post',
           configEnvironment(name, config) {
-            if (name === 'ssr' && config.resolve?.conditions) {
-              config.resolve.conditions = config.resolve.conditions.filter(x => x !== 'import')
-            }
+            if (name === 'ssr' && config.resolve?.conditions) {
+              return {
+                resolve: {
+                  conditions: config.resolve.conditions.filter(x => x !== 'import'),
+                },
+              }
+            }
           },
         },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/config.ts` around lines 219 - 228, The
`nuxt:test-utils:patch-ssr-conditions` plugin in `configEnvironment` is mutating
`config.resolve.conditions` directly, but Vite recommends returning a partial
config instead. Update `configEnvironment(name, config)` so that when `name ===
'ssr'` and conditions include `'import'`, it returns a partial `{ resolve: {
conditions: [...] } }` object with `'import'` removed, instead of editing
`config` in place. Keep the existing behavior and guard around
`config.resolve?.conditions`, but express the change through the returned config
object to match the documented `configEnvironment` pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/config.ts`:
- Around line 219-228: The `nuxt:test-utils:patch-ssr-conditions` plugin in
`configEnvironment` is mutating `config.resolve.conditions` directly, but Vite
recommends returning a partial config instead. Update `configEnvironment(name,
config)` so that when `name === 'ssr'` and conditions include `'import'`, it
returns a partial `{ resolve: { conditions: [...] } }` object with `'import'`
removed, instead of editing `config` in place. Keep the existing behavior and
guard around `config.resolve?.conditions`, but express the change through the
returned config object to match the documented `configEnvironment` pattern.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8f257c1b-c35d-453d-9397-04406c8a7321

📥 Commits

Reviewing files that changed from the base of the PR and between 5acf9c1 and 1a73d75.

📒 Files selected for processing (1)
  • src/config.ts

Comment thread src/config.ts Outdated
enforce: 'post',
configEnvironment(name, config) {
if (name === 'ssr' && config.resolve?.conditions) {
config.resolve.conditions = config.resolve.conditions.filter(x => x !== 'import')

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.

should this live in the plugin above?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you.
config.ssr.resolve.conditions was causing the issue.
updated it to adjust config.ssr via the configResolved hook and unified it into the plugin above.

@yamachi4416 yamachi4416 changed the title fix(config): add patch environments.ssr.resolve.conditions fix(config): add patch ssr.resolve.conditions Jul 4, 2026
@danielroe danielroe changed the title fix(config): add patch ssr.resolve.conditions fix(config): patch ssr.resolve.conditions to remove import Jul 14, 2026
@danielroe
danielroe merged commit 3831454 into nuxt:main Jul 14, 2026
10 checks passed
This was referenced Jul 13, 2026
@yamachi4416
yamachi4416 deleted the patch-ssr-resolve-conditions branch July 18, 2026 04:34
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.

Import of postgres ("pg") breaks when using nuxt test-utils in combination with vitest >= 4.1.0

2 participants