void/db imported from schema files outside db/schema.ts causes a circular import (sql is not a function)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 53/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- sqlite, typescript, vite
- Domain
- backend, build-system
Research direction
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.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- TypeScript
- Stars
- 402
- Forks
- 32
- Avg merge
- 12h 28m
- Merged PRs (30d)
- 77
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from voidzero-dev/void
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
voidzero-dev/void#478 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
voidzero-dev/void#463 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
voidzero-dev/void#459 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
voidzero-dev/void#428 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
voidzero-dev/void#480 ·
Maintainers usually reply within 1 day
All issues in voidzero-dev/void
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ccch1mneyyy/dsh-TUI#1631 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MiniMax-AI/minimax-code#507 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Transient OAuth login failure persists in getLoginStatus and masks active account in dashboardMay be free again A pull request for this issue was closed without being merged. Openaccount-pool bug gui
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
lidge-jun/opencodex#7378 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day