tursodatabase/turso · error · Error

HTTP request missing URL: no URL in request and no baseUrl…

Error message

HTTP request missing URL: no URL in request and no baseUrl in context

What it means

The sync engine emitted an HTTP IO item, but the request carried no URL and the IoContext has no usable baseUrl (the url from your connect options). processHttpRequest refuses to guess and throws. The IoContext baseUrl is only populated from DatabaseOpts.url, and empty strings and null-returning url functions both count as missing.

Solutions

  1. Pass a concrete url (e.g. libsql://mydb.turso.io) in the connect options whenever you intend to sync
  2. If url is a function, make it return the real URL string (or throw early) - never null
  3. Fail fast at startup: validate that opts.url is a non-empty string before calling connect

Example fix

// before
const db = new Database({ path: 'replica.db', url: process.env.SYNC_URL }); // '' in release

// after - fail fast on missing configuration
const url = process.env.SYNC_URL;
if (!url) throw new Error('SYNC_URL is required for sync mode');
const db = await connect({ path: 'replica.db', url });
Defensive patterns

Strategy: validation

Validate before calling

function assertSyncUrl(opts: DatabaseOpts): void {
  const url = typeof opts.url === 'function' ? opts.url() : opts.url;
  if (opts.path !== ':memory:' && !url) {
    throw new Error('A non-empty url is required for sync mode');
  }
}
// call before connect(opts)

Type guard

function hasSyncUrl(opts: DatabaseOpts): boolean {
  const url = typeof opts.url === 'function' ? opts.url() : opts.url;
  return typeof url === 'string' && url.length > 0;
}

Prevention

When it happens

Trigger: Opening a Database with url: '' (empty string still selects sync mode via isSyncConfig) and then calling connect()/pull()/push(); passing url as a function that returns null; invoking a network-touching operation on a database whose sync options were never wired.

Common situations: url built from an env/config variable that is undefined in the release build, producing '' after template-string interpolation; a url provider function that returns null before a remote config fetch completes.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/9061718ba693d31f. Report an issue: GitHub.

Appendix: source

Thrown at bindings/react-native/src/internal/ioProcessor.ts:162

    return context.baseUrl() ?? null;
  }

  return context.baseUrl;
}

/**
 * Process an HTTP request using fetch()
 *
 * @param item - The IO item
 * @param context - IO context with auth and URL information
 */
async function processHttpRequest(item: NativeSyncIoItem, context: IoContext): Promise<void> {
  const request = item.getHttpRequest();

  // Resolve base URL: prefer context.baseUrl (from opts), fall back to request.url
  const rawBaseUrl = getBaseUrl(context) ?? request.url;
  if (!rawBaseUrl) {
    throw new Error('HTTP request missing URL: no URL in request and no baseUrl in context');
  }

  // Normalize URL (libsql:// -> https://)
  const baseUrl = normalizeUrl(rawBaseUrl);

  // Build full URL by combining base URL with path
  let fullUrl = baseUrl;
  if (request.path) {
    // Ensure proper URL formatting (avoid double slashes, ensure single slash)
    if (baseUrl.endsWith('/') && request.path.startsWith('/')) {
      fullUrl = baseUrl + request.path.substring(1);
    } else if (!baseUrl.endsWith('/') && !request.path.startsWith('/')) {
      fullUrl = baseUrl + '/' + request.path;
    } else {
      fullUrl = baseUrl + request.path;
    }
  }

View on GitHub (pinned to 244cde92a7)