Packaged Convex Components
Read this file when the user wants a reusable npm package or a component shared across multiple apps.
When to Choose This
- The user wants to publish the component
- The user wants a stable reusable package boundary
- The component will be shared across multiple apps or teams
Default Approach
- Prefer starting from
npx create-convex@latest --componentwhen possible - Keep the official authoring docs as the source of truth for package layout and
exports
- Validate the bundled package through an example app, not just the source files
Build Flow
When building a packaged component, make sure the bundled output exists before the example app tries to consume it.
Recommended order:
npx convex codegen --component-dir ./path/to/component- Run the package build command
- Run
npx convex dev --typecheck-componentsin the example app
Do not assume normal app codegen is enough for packaged component workflows.
Package Exports
If publishing to npm, make sure the package exposes the entry points apps need:
- package root for client helpers, types, or classes
./convex.config.jsfor installing the component./_generated/component.jsfor the app-facingComponentApitype./testfor testing helpers when applicable
Testing
- Use
convex-testfor component logic - Register the component schema and modules with the test instance
- Test app-side wrapper code from an example app that installs the package
- Export a small helper from
./testif consumers need easy test registration
Checklist
- [ ] Packaging is actually required
- [ ] Build order avoids bundle and codegen races
- [ ] Package exports include install and typing entry points
- [ ] Example app exercises the packaged component
- [ ] Core behavior is covered by tests