Skip to content

fix(auth): load auth.ts through Vite in builds and void prepare - #611

Merged
Brooooooklyn merged 3 commits into
fix/svelte-use-params-refreshfrom
fix/auth-config-build-loader
Oct 27, 2026
Merged

Brooooooklyn merged 3 commits into
fix/svelte-use-params-refreshfrom
fix/auth-config-build-loader

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Problem

Dev loads auth.ts through a Vite module runner. vite build and void prepare (also void gen / void db) still used Node's own import(). So an auth.ts with a normal import failed there, while dev worked:

import { origins } from './lib/origins'   // no extension
import { fields } from '@schema/fields'   // Vite alias
Error: Cannot find module '.../lib/origins' imported from .../auth.ts

The loader also took export const auth / export const config. The Worker only imports the default export, so the schema could be built from a config the runtime never reads.

Fix

          before                    after
dev     : dev env runner       ->  dev env runner (no change)
build   : import()  ✗          ->  runnerImport + build's resolve.alias / tsconfigPaths
prepare : import()  ✗          ->  runnerImport + alias / tsconfigPaths from the app's resolved vite config (plugins included)
named export only : accepted   ->  "<path> has no default export. Export the auth config with `export default defineAuth(...)`."
  • viteAuthConfigImporter(root, mode, resolve) runs auth.ts once with Vite's runnerImport.
  • projectAuthConfigImporter(root) is for commands outside Vite. It resolves the app's vite config with its plugins (resolveConfig, serve, development), only when an auth.ts exists. Aliases that plugins add in config(), such as Void's @schema, are included.
  • devAuthConfigImporter(server) always gives an importer: the auth config environment, or else a runner with the dev server's resolved aliases.
  • loadVoidAuthConfig now needs an importer and accepts only a default export.

Tests

  • void prepare in a plain node child process (Vitest's runner would hide the bug): auth.ts imports an extensionless file, an alias from vite.config, and @schema added by a plugin's config() hook. All three fields reach the generated schema.
  • Build: routingPlugin buildStart with a resolved build config that has an alias. Same check.
  • Dev server without the auth config environment: the importer resolves an alias from the server's config.
  • A named-only export gives the clear error.
  • Each guarded change, reverted on its own, makes one of these tests fail.

Choices to check

  • Only resolve.alias and resolve.tsconfigPaths are passed on to the runner, not plugins. A plugin that resolves imports in resolveId without an alias is not applied to auth.ts outside dev.
  • Apps with auth.ts now resolve their vite config (with plugin config() / configResolved() hooks) during void prepare. That adds about 1s, and an error in the vite config or a plugin hook now stops prepare.
  • Named-only auth exports are now an error. They never worked at runtime.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T08:07:20.434415Z 106d132 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Brooooooklyn

Copy link
Copy Markdown
Member Author

@codex review

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-auth-config-build-loader-void-cloud.voidzero-docs.workers.dev (commit 106d132)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://5f5ce568-void-cloud.voidzero-docs.workers.dev 106d132 2026-10-27T08:06:34.932Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://76f9e5eb-void-cloud.voidzero-docs.workers.dev 7e8d32a 2026-10-27T07:55:36.276Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://6f414fa5-void-cloud.voidzero-docs.workers.dev b1e2ab9 2026-10-27T07:20:48.596Z Visit the dashboard ↗

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: b1e2ab9580

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Brooooooklyn and others added 2 commits October 27, 2026 15:46
Dev already loads auth.ts through a Vite module runner, but `vite build`,
`void prepare` and the CLI commands that run it still used a plain Node
`import()`. An auth.ts that imports a project file without an extension
(`import './db'`) or through a Vite alias (`@schema/...`) failed there
with "Cannot find module", even though dev worked.

Builds and CLI commands now evaluate auth.ts once with Vite's
`runnerImport`, so imports resolve as in dev. A build passes its own
resolved aliases and `tsconfigPaths`; `void prepare` reads them from the
app's Vite config.

The loader also accepted `export const auth` or `export const config`,
but the Worker only imports the default export, so the generated schema
and the runtime could disagree. It now requires a default export and says
to use `export default defineAuth(...)`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`void prepare`, `void gen` and `void db generate` read only the raw
vite.config to find aliases for auth.ts. Aliases that plugins add in
their `config()` hook were missing, such as Void's own `@schema`, so an
auth.ts with `import { ... } from '@Schema'` failed with "Cannot find
module '@Schema'" there, while dev and build worked.

These commands now resolve the app's Vite config with its plugins and
use its aliases. When the dev server has no auth config environment, the
migration fallback uses the server's resolved aliases too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn
Brooooooklyn force-pushed the fix/auth-config-build-loader branch from b1e2ab9 to 7e8d32a Compare October 27, 2026 07:54
@Brooooooklyn
Brooooooklyn changed the base branch from main to fix/svelte-use-params-refresh October 27, 2026 07:55
@Brooooooklyn
Brooooooklyn added this pull request to stack #618 October 27, 2026 07:56
`void prepare`, `void gen` and `void db generate` loaded the app's
vite.config to find aliases for auth.ts. Evaluating it constructs the
app's plugins, and Void's plugin writes generated files and Cloudflare
config when constructed, so preparing types could change the project.
`void prepare` must not boot the app's Vite.

These commands now evaluate auth.ts without the app's Vite config.
Imports still resolve without extensions, through tsconfig `paths`, and
through Void's own `@schema` alias. An alias set only in vite.config
resolves in dev and builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member Author

Fixed in 106d132 on #611, which this PR is stacked on. void prepare, void gen and void db generate no longer load the app's vite.config: auth.ts is evaluated with Vite's runnerImport (no config file), using tsconfig paths and Void's own @schema alias. The prepare test now has a vite.config that writes a marker file and checks it is never written.

@Brooooooklyn
Brooooooklyn enabled stacked auto-merge (squash) October 27, 2026 08:34
stacked auto-merge was automatically disabled October 27, 2026 08:34

Auto-merge was disabled for another pull request in the stack

@Brooooooklyn
Brooooooklyn merged commit cda7f0a into main Oct 27, 2026
20 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/auth-config-build-loader branch October 27, 2026 08:51
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.

2 participants