Skip to content

This notebook belongs to

Sadat Jubayer

Senior Software Engineer at Premio

If found, please return to hello@jubayer.dev

Vol. 7Seven years of building

Started
January 2020
Everyday tools
TypeScript, Vue, React, Next.js, NestJS, React Native
Education
B.Sc. CSSE, AIUB, 2020
2 min readDev Tool

Keep browser exports when upgrading to Vite 6

Check custom resolve.conditions before upgrading to Vite 6 so packages with conditional exports keep their intended browser entry in your bundle.

You upgrade a browser app from Vite 5 to Vite 6. The build passes, but a dependency now takes its fallback code path. If your Vite config sets resolve.conditions, compare the package entry Vite chooses before and after the upgrade.

Find the condition that dropped out

Open a dependency's package.json and inspect its exports field. A package can provide a browser entry and a default entry at the same subpath. A bundler can use the browser file if browser is an active condition. Put the default branch after the more specific branches in the package’s exports map.

Consider a Vite 5 app that sets resolve.conditions to ['partner']. Vite 5 still supplies some other conditions internally, including browser for the client build. In Vite 6, browser lives in the default client list. Keeping your old ['partner'] array replaces that list and leaves browser out.

An app with no custom condition array gets those defaults. Check the config that actually reaches the build, including shared config files and helpers. A custom list can come from a preset even if you see no resolve block in the app's own file.

Restore the client defaults

In vite.config.mjs, retain your custom conditions and spread the default client conditions from Vite.

import { defaultClientConditions, defineConfig } from 'vite'

export default defineConfig({
  resolve: {
    conditions: ['partner', ...defaultClientConditions],
  },
})

A dependency with a browser entry followed by a default entry in its exports map can now resolve to the browser file again.

Think of the array as the set of conditions Vite can match. A package's exports map decides which matching branch comes first. Putting partner at the front of your Vite array leaves the order of keys in the package's exports map intact.

Run npm exec -- vite build in the app with Vite 6 installed. Check a feature backed by a dependency with distinct browser behavior. In a scratch package, you can export a different string from each branch and look for the marker in the output. Use the marker to check which entry Vite bundled.

In a scratch build, the old custom condition array selected BROWSER_ENTRY on Vite 5 and FALLBACK_ENTRY on Vite 6. Spreading the defaults restored BROWSER_ENTRY.

If your app also builds for SSR, inspect ssr.resolve.conditions as its own setting. The Vite 6 migration guide gives a distinct list for the server and covers externalized dependencies. Verify the browser result first, then run the production server path against any server-specific dependency.