Skip to content

Environment API: noExternal configuration inconsistency between top-level and environment-level settings #20098

Open
@jasonkuhrt

Description

@jasonkuhrt

Documentation is

  • Missing
  • Outdated
  • Confusing
  • Not sure?

Explain in Detail

When using Vite 6's experimental Environment API with SSR builds, there's an undocumented requirement that ssr.noExternal must be configured at the top level of the configuration rather than at the environment level to actually bundle dependencies.

Current Behavior

❌ This doesn't work (dependencies are externalized):

{
  environments: {
    ssr: {
      build: {
        noExternal: true, // ← This has no effect
        rollupOptions: {
          input: 'virtual:my-ssr-entry'
        }
      }
    }
  }
}

✅ This works (dependencies are bundled):

{
  ssr: {
    noExternal: true, // ← Must be at top level
  },
  environments: {
    ssr: {
      build: {
        rollupOptions: {
          input: 'virtual:my-ssr-entry'
        }
      }
    }
  }
}

Your Suggestion for Changes

Expected Behavior

When using the Environment API, I would expect noExternal configuration to work at the environment level:

{
  environments: {
    ssr: {
      noExternal: true, // ← Should work here
      build: {
        rollupOptions: {
          input: 'virtual:my-ssr-entry'
        }
      }
    }
  }
}

Reproduction

No response

Steps to reproduce

Reproduction

  1. Create a Vite plugin that configures an SSR environment:
{
  name: 'ssr-plugin',
  apply: 'build',
  applyToEnvironment: (env) => env.name === 'ssr',
  config() {
    return {
      environments: {
        ssr: {
          build: {
            noExternal: true, // This doesn't work
            rollupOptions: {
              input: 'my-entry.js'
            }
          }
        }
      }
    }
  }
}
  1. Build with the Environment API
  2. Observe that dependencies are externalized (showing import statements instead of bundled code)
  3. Move noExternal: true to top-level ssr.noExternal and dependencies get bundled correctly

Environment

  • Vite version: 6.3.5
  • Node version: [your node version]
  • OS: [your OS]

Additional Context

This behavior suggests either:

  1. Documentation gap: The Environment API docs should clarify which settings remain at the top level vs. environment level
  2. Potential bug: noExternal should be respected when configured at the environment level
  3. Design limitation: Some SSR settings may intentionally remain global rather than per-environment

The current SSR Options documentation only covers the traditional top-level configuration, and the Environment API documentation doesn't specify this interaction.

This issue affects anyone trying to use the new Environment API for SSR builds and expecting environment-scoped configuration to work consistently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions