Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

void/db imported from schema files outside db/schema.ts causes a circular import (sql is not a function)

Aperta
#472 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
53/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
sqlite, typescript, vite

Direzione di ricerca

Start with the Vite plugin logic in the dist/dispatch-*.mjs files mentioned in the report, then trace how it resolves void/db for db/schema.ts and re-exported schema files. Reproduce the cycle with the supplied D1/SQLite schema example in a Vite runtime. Done means the reported route can import the table without sql is not a function, or the project documents a supported alternative for sql in re-exported schema files.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

Importing sql from void/db in a table file that is re-exported from db/schema.ts, rather than defined in it, fails at runtime with:

TypeError: vite_ssr_import_0.sql is not a function

Reproduction

// db/schema.ts:
export * from "../src/resources/projects/projects.schema";

// src/resources/projects/projects.schema.ts:
import { sql } from 'void/db';
import { sqliteTable, text, integer } from 'void/schema-d1';

export const projects = sqliteTable('projects', {
  id: integer('id').primaryKey({ autoIncrement: true }),
  createdAt: text('created_at').notNull().default(sql`(datetime('now'))`),
});

Request any route that imports the table (e.g. via a repository).

Cause (from reading dist/dispatch-*.mjs)

The Vite plugin treats void/db as virtual:void-db-schema (no schema import) only when the importer is exactly db/schema.ts. Any other file gets virtual:void-db, which does import * as schema from db/schema.ts. That gives the cycle:

projects.schema.ts -> virtual:void-db -> db/schema.ts -> projects.schema.ts

sql is used at module top level while virtual:void-db is still evaluating, so it is undefined. tsc and void db generate don't catch it; only the Vite runtime does.

Similar to #50 (same error, caused by Windows path separators), but this one happens on Linux with a re-exported schema layout.

Expected

Either schema files reachable from db/schema.ts get the schema-free module too, or the docs say schema files other than db/schema.ts must not import void/db (and show an alternative for sql).

Environment

  • void 1.1.11
  • Linux
  • D1 / sqlite
Lingua principale
TypeScript
Stelle
402
Fork
32
Merge medio
13h 14m
PR unite (30g)
73

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di voidzero-dev/void

Tutte le issue di voidzero-dev/void

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.