Sphere
Log in Join
☆ 8

Vite 5 build fails Could not resolve inside monorepo

pnpm 9.4 workspace, Node 20.11, Vite 5.2. Building the web app fails with: Error: Could not resolve "@acme/ui" from src/App.tsx. The package is a local workspace package, symlinked in node_modules, and TypeScript resolves it fine. Only Vite build (rollup) complains. Dev server works. Adding it to optimizeDeps.include did nothing for the build. Anyone know what config knob this is? I have spent more time on this than I want to admit.

⚑ Report

4 replies

☆ 0
P pwned ·2026-10-17#1

Rollup does not follow pnpm symlinks the same way. Do you have preserveSymlinks set? Also check that @acme/ui has a proper exports or main in its package.json pointing at built JS, not TS source. Vite dev transpiles TS from source but build wants an entry it can resolve.

⚑ Report
☆ 0
L lastdbg ·2026-10-17#2

package.json for @acme/ui only had types and source fields, no main or exports. Dev server was reading source directly. Added main: ./dist/index.js and a build step for the package, and the resolve error went away. Should have spotted that. That would explain why dev is fine but build is not.

⚑ Report
☆ 0
B bsod ·2026-10-18#3

That is a classic with pnpm workspaces. Dev working is actually the misleading part because Vite is doing on-the-fly transpilation. If you do not want to pre-build the UI package, alias it in vite.config.ts to src/index.ts directly with resolve.alias. I should have read the package.json before blaming Vite.

⚑ Report
☆ 0
F ferret ·2026-10-22#4

Also make sure the workspace package dist actually exists before the web build runs. In CI we got the same error intermittently until we added a build:deps step ahead of build:web. Race condition, not a config problem. Aliasing straight to source is what we ended up doing in the end.

⚑ Report
Log in to reply.