Skip to content

vite dev: externalized dependencies resolve with the development condition, so a package can load twice #4994

Closed

Description

@dennev

Environment

nitro 3.0.261029-rc, vite 8.3.5, Node.js 24.21.0, Linux, the default dev runner.

Reproduction

https://github.com/dennev/nitro-dev-external-conditions

Describe the bug

In vite dev, the nitro environment's resolve.externalConditions is ["development", "node"]: Nitro adds development to its export conditions in dev, and _externalConditions in src/build/vite/env.ts keeps it, where Vite's default is ["node", "module-sync"]. Node then resolves the imports inside those externalized files without development.

So an externalized dependency with a development export runs twice when another externalized dependency imports it too: its development build from the app's import, and its default build from the other dependency's import. Code that compares across the two copies breaks.

The reproduction has a small package dual and a package consumer that imports it. With seroval and seroval-plugins 1.6.9 it also serializes a ReadableStream:

Run App imports dual consumer imports dual seroval stream
vite dev development default SerovalUnsupportedTypeError
vite dev, development removed from the external conditions default default ok
vite build, then node .output/server/index.mjs default default ok

With both at 1.7.0 or 1.7.6 the stream is ok, because the plugin no longer hands the parser a Stream from its own copy of seroval, but dual still splits.

I intend to send a pull request, with a failing test first, once the direction is clear.

Additional context

The same failure happens on 3.0.260903-beta.

exportConditions: ["!development"] in the Nitro config avoids the split today, but it also takes the condition out of the environment's resolve.conditions, which becomes ["wasm", "unwasm", "node"].

Dropping development from the external conditions fixes the reproduction, as the second row shows, and Vite's default has no development either. A project that wants development builds would lose them for its direct imports, and one that starts Node with --conditions=development would get the same split the other way round: the app gets the default build, consumer the development build, and the stream fails. The other direction is to start the dev worker with that flag, so that Node and Vite agree: with NODE_OPTIONS=--conditions=development and today's conditions, both sides get the development build and the stream is ok. Which do you prefer?

statelyai/agent#166 hit the same cause and drops development from the server externalConditions with a Vite plugin. solidjs/solid-vite-plugin#397 describes the same two seroval copies in dev and inlines them.

Activity

  1. added
    vite
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vite

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions