Registry / database / convex

convex

JSON →
library0.7.0jsnpmunverified

Convex is a comprehensive backend application platform offering a real-time database, serverless functions (queries, mutations, actions), and client libraries for JavaScript/TypeScript, with strong support for React. The current stable version is 1.36.0, with frequent precompiled releases indicating rapid development and continuous improvements. A key differentiator is its real-time reactivity, where client-side `useQuery` hooks automatically update whenever the underlying database data changes, eliminating manual subscription management. It provides end-to-end type safety, optional schema definitions, and a TypeScript-first approach for both backend function definitions and client-side consumption. The platform includes SDKs for defining backend logic, integrating with React, and handling authentication with providers like Auth0 and Clerk. Convex aims to simplify full-stack development by unifying the database and backend logic within a single reactive environment.

npm install convex
INSTALL
IMPORT
SIG · CONVEX
C
convex
databasejavascriptv0.7.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ConvexReactClient
import { ConvexReactClient } from 'convex/react';
const ConvexReactClient = require('convex/react');
The Convex client for React applications. Typically instantiated once and passed to `ConvexProvider`.
useQuery
import { useQuery } from 'convex/react';
import useQuery from 'convex/react';
React hook for fetching real-time data from Convex queries. Requires `api` object from `_generated/api`.
query
import { query } from 'convex/server';
import { query } from 'convex/react';
Used in Convex backend files (e.g., `convex/myFunctions.ts`) to define read-only database functions.
mutation
import { mutation } from 'convex/server';
import { mutation } from 'convex';
Used in Convex backend files to define write operations to the database. These run as transactions.
v
import { v } from 'convex/values';
import { s } from 'convex/schema';
Validator object for defining schema and function arguments. Renamed from `s` in `convex/schema` since v0.13.0.
api
import { api } from '../convex/_generated/api';
Generated client-side API object for calling Convex backend functions. Path is relative to your client code.

This quickstart demonstrates how to set up the Convex React client, connect to a Convex backend, and display real-time data fetched using the `useQuery` hook within a React component. It assumes a basic backend query `getTasks` is defined.

import React from 'react'; import { ConvexReactClient, ConvexProvider, useQuery } from 'convex/react'; import { api } from '../convex/_generated/api'; // Adjust path as needed // Initialize the Convex client const convexUrl = process.env.VITE_CONVEX_URL ?? 'https://your-convex-url.convex.cloud'; // Replace with your actual URL or env var const convex = new ConvexReactClient(convexUrl); // Backend function definition (e.g., in convex/tasks.ts) /* import { query } from './_generated/server'; import { v } from 'convex/values'; export const getTasks = query({ args: { status: v.optional(v.string()) }, handler: async (ctx, args) => { return await ctx.db.query('tasks') .filter(q => args.status ? q.eq(q.field('status'), args.status) : true) .collect(); }, }); */ interface Task { _id: string; text: string; status: 'todo' | 'done'; } function TaskList() { // Fetch tasks in real-time. The component re-renders when data changes. const tasks = useQuery(api.tasks.getTasks, { status: 'todo' }); if (tasks === undefined) { return <div>Loading tasks...</div>; } if (tasks.length === 0) { return <div>No tasks to display.</div>; } return ( <div> <h1>Todo List</h1> <ul> {tasks.map((task: Task) => ( <li key={task._id}>{task.text}</li> ))} </ul> </div> ); } export default function App() { return ( <ConvexProvider client={convex}> <TaskList /> </ConvexProvider> ); }
convex --version
Debug
Known issues
breakingConvex function arguments changed from multiple positional arguments to a single arguments object. Additionally, the schema builder `s` moved from `convex/schema` to `v` in `convex/values`, and several client APIs (`ConvexReactClient`, `ConvexHttpClient`) were updated for consistency.
fix
Update backend functions to accept a single object for arguments. Migrate schema definitions to use `import { v } from 'convex/values;'`. Review client-side API calls for `ConvexReactClient` and `ConvexHttpClient`.
affects: >=0.13.0
breakingThe `ctx.db.get`, `patch`, `replace`, and `delete` functions now require the table name as the first argument, e.g., `ctx.db.get("tableName", id)`. While previous syntax is still supported, it will be deprecated.
fix
Update database interaction calls in your backend functions to explicitly include the table name as the first argument. Automatic migration tools (ESLint rule, codemod) are available.
affects: >=1.31.0
deprecatedNode.js 18 support is being deprecated, with new projects defaulting to Node.js 20. Existing Node.js 18 projects will be automatically migrated to Node.js 20 by October 22, 2025.
fix
Ensure your development and deployment environments are using Node.js 20 or later to avoid future compatibility issues and take advantage of new features.
affects: >=1.26.0
gotchaWhen using `useQuery` within React components, `ctx.auth.getUserIdentity()` can initially return `null` if the Convex client has not yet fully authenticated, even if the user is logged in.
fix
Wrap components containing authenticated `useQuery` calls with Convex's `Authenticated` component or explicitly handle `null` results from the query on the client-side, potentially rendering a loading state or fallback UI.
affects: >=0.13.0
gotchaReact Hooks cannot be called conditionally. Using `useQuery` inside an `if` statement or conditional block will lead to runtime errors.
fix
For conditional data fetching, pass the special string `'skip'` as the arguments to `useQuery` when the query should not run, for example: `useQuery(api.myFunc, condition ? { arg: 'value' } : 'skip');`
affects: all
gotchaCircular imports in your Convex backend files, especially involving `schema.ts`, can lead to 'Undefined validator' errors at runtime.
fix
Refactor your import structure to break circular dependencies. Often, this involves moving common validators or table definitions into a separate file that does not import back from `schema.ts`.
affects: all
Errors
Common errors & fixes
Error: VITE_CONVEX_URL is not defined
The environment variable for the Convex deployment URL is missing or incorrectly named.
fix
Create a `.env` file in your project root with `VITE_CONVEX_URL=https://your-convex-url.convex.cloud` (or `CONVEX_URL` for Node.js environments) and restart your development server.
ctx.auth.getUserIdentity() returns null in a query
The client-side authentication process has not completed by the time the `useQuery` hook attempts to fetch data, or the user is not signed in.
fix
Ensure the user is authenticated before calling queries that rely on `ctx.auth.getUserIdentity()`. Use Convex's `Authenticated` React component or handle the `null` identity gracefully within your client-side component, showing a loading or unauthenticated state.
Type errors in api imports
The TypeScript types for your Convex backend functions (located in `convex/_generated/api.d.ts`) are out of sync with your latest backend code.
fix
Run `npx convex dev` (or `npx convex codegen` if not running `dev`) to regenerate the TypeScript types. Ensure your `convex/` directory is properly set up.
Write conflict: Optimistic concurrency control
A Convex mutation failed to commit because the underlying data it read changed due to another concurrent mutation. This leads to retries and can indicate contention on specific documents.
fix
Refactor mutations to read less data, use more specific indexed queries, or reduce concurrent writes to the same document. For high-contention scenarios, rethink the data model to spread writes across more documents.
Upgrade
Version history
0.7.0latest on npm
Audit
Dependencies
@auth0/auth0-reactoptionalOptional peer dependency for Auth0 authentication integration.
@clerk/clerk-reactoptionalOptional peer dependency for Clerk authentication integration.
@clerk/reactoptionalOptional peer dependency for Clerk authentication integration.
reactrequiredRequired for using the React client library and hooks.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources
convex — npm install convex · libregistry