Skip to content

fix(db): resolve Nuxt aliases in schema declarations - #954

Merged
atinux merged 1 commit into
mainfrom
fix/db-schema-types-aliases
Nov 12, 2026
Merged

atinux merged 1 commit into
mainfrom
fix/db-schema-types-aliases

Conversation

@atinux

@atinux atinux commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Written by an AI agent on behalf of @atinux.
Closes #934

Problem

buildDatabaseSchema passes nuxt.options.alias to the JS bundle, but the declaration build runs tsc with tsconfig: false and no paths. A schema file that imports through a Nuxt alias, such as a layer's orders table importing user from #auth/schema, works at runtime but gets any in @nuxthub/db's types (user: One<any, true>).

What changed

  • The dts step now gets the same aliases as the JS bundle, as tsc compilerOptions.paths: alias and alias/* for each one.
  • When a target ends in .js, .mjs or .cjs, the path without the extension is tried first, so tsc finds the .d.ts beside it. This is what Nuxt's own tsconfig does. Given a path with an extension, tsc loads that exact file, and a .mjs file is any. The original path stays as a fallback, for directories whose names end in .js.
  • SCHEMA_TYPES_CACHE_VERSION goes to 2, so declarations cached with the old options are rebuilt.

Evidence

New test resolves Nuxt aliases in schema types in test/database.schema-build.test.ts. It covers a file alias (.mjs with a .d.ts beside it) and a directory alias (#shared/status).

Before the fix, the generated schema.d.mts was:

declare const orders: {
  user: any;
  status: any;
};

After the fix, the test passes, along with the rest of database.schema-build.test.ts and database.config.test.ts (53 tests).

I also ran the reporter's repro with this branch linked in and the cache cleared, then ran nuxt typecheck. Check 2 is the layer relation to user:

@nuxtjs/better-auth patch This PR Check 2 ordersRelations.user
applied no fails One<any, true>
applied yes passes, typecheck is clean One<"user", true>
not applied yes fails One<any, true>

Note

The issue says the core change turns check 2 green on its own. I couldn't reproduce that, and the reporter's own patch didn't do it either when I tried. @nuxtjs/better-auth points #auth/schema at a .mjs file with no declarations beside it, so tsc has nothing to type it with. Fully fixing the repro also needs nuxt-modules/better-auth#506.

ELI5

The database types are built by a separate step that didn't know the app's import shortcuts, so anything imported through a shortcut was typed as "anything". That step now gets the same shortcuts as the rest of the build.

The declaration build ran tsc without the Nuxt aliases that the JS bundle
uses, so aliased imports in schema files were typed `any` in @nuxthub/db.

Closes #934

Amp-Thread-ID: https://ampcode.com/threads/T-01a1cfeb-885a-7730-904a-ed32f015a120
@vercel

vercel Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nuxthub Ready Ready Preview Nov 12, 2026 1:37pm UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 12, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxthub/core@954

commit: c3bef3a

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
playground c3bef3a Commit Preview URL

Branch Preview URL
Nov 12 2026, 01:37 PM

@atinux
atinux merged commit 5772ded into main Nov 12, 2026
10 checks passed
@atinux
atinux deleted the fix/db-schema-types-aliases branch November 12, 2026 20:14
@github-actions github-actions Bot mentioned this pull request Nov 12, 2026

This branch was successfully deployed

1 active deployment
Preview — c3bef3a2 Deployed Nov 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(db): schema declarations ignore Nuxt aliases

1 participant