convex-js
convex-js copied to clipboard
`externalPackages` doesn't work in monorepos
External Packages Fail in Monorepos Due to Dependency Hoisting - Major DX Issue
Description
There's a significant issue when using Convex's externalPackages for node envs feature within monorepos. The current implementation doesn't account for monorepo package management, where dependencies are typically hoisted to the root. This affects ALL external packages, with Sharp being a prime example in my case.
Problem Scope
This is NOT just a Sharp-specific issue - it affects any external package used with Convex in a monorepo setup.
The externalPackages feature expects packages in the local node_modules, and since monorepos hoist the dependecies to the root, convex is unable to find them.
Current Behavior When using ANY external package in a monorepo:
- Dependencies are hoisted to root
node_modules(standard monorepo behavior) - Convex can't locate the package even when it's in root
package.json - Deployment fails due to missing dependencies
- Adding to root
package.jsonis insufficient - must also add to the Convex app'spackage.json
Example with Sharp
monorepo/
├─ node_modules/ (where packages actually live)
├─ apps/
│ ├─ convex-app/
│ │ ├─ node_modules/ (where Convex expects packages)
│ │ ├─ package.json (needs duplicate declaration)
Current Workaround (Hacky)
- Create manual
node_modulesinside the Convex app directory - Physically copy package files from root node_modules
- Add duplicate package entries in both root and app
package.json - Configure as
externalPackage
Suggested Solutions
- Short-term: Document this limitation clearly in the
externalPackagesdocs - Medium-term: Add monorepo detection and automatic package location resolution
- Long-term: Redesign the
externalPackagesfeature to work with hoisted dependencies
Environment
- Package Managers Affected: pnpm, yarn, npm, bun (all with workspaces)
- Monorepo Tools: Turborepo, Nx, others
- Convex Version: ^1.14.4