Dev: `better-auth/client/plugins` fails to resolve when auth is enabled (the `better-auth/client` alias matches it as a prefix)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript, vite
- 领域
- devtools
调研方向
阅读 packages/void/src/plugin-routing.ts 中第 616–622 行附近的 Better Auth 别名,并检查 Vite 如何将字符串别名与子路径匹配。启用身份验证,并从 better-auth/client/plugins 导入以重现问题;比较开发环境中的解析结果与构建行为。完成标准是插件导入可在 void dev 中解析,同时现有的 Better Auth 别名继续正常工作。
由索引模型根据 Issue 内容生成。
描述
Description
With auth enabled, void dev aliases better-auth/client (and /react, /vue, /svelte, /solid) to absolute file paths. A string alias in Vite also matches subpaths, so better-auth/client/plugins, where Better Auth's client plugins such as adminClient() live, is rewritten to …/better-auth/dist/client/index.mjs/plugins, which doesn't exist. Any app that passes a Better Auth client plugin to createAuthClient breaks in dev. void build is not affected, because the alias is only added for serve.
Steps to reproduce
-
Enable auth in
void.config.ts:auth: { providers: ['email'] }. -
Add
better-authas a dependency (the same version Void uses). -
Create a client with a plugin and import it from a page:
// src/lib/auth-client.ts import { adminClient } from 'better-auth/client/plugins'; import { createAuthClient } from 'void/client'; export const authClient = createAuthClient({ basePath: '/api/auth', plugins: [adminClient()], }); -
Run
void devand open that page.
Actual behavior
- Client:
Pre-transform error: Failed to resolve import "better-auth/client/plugins" from "src/lib/auth-client.ts". Does the file exist? - SSR: the page returns 500 with
Error: No such module "workers/runner-worker/file:/…/better-auth/dist/client/plugins/index.mjs".
Expected behavior
better-auth/client/plugins resolves to better-auth/dist/client/plugins/index.mjs, as it does in void build and in Node.
Cause
packages/void/src/plugin-routing.ts (main @ 6ba3dbcc3a, lines 616–622):
const betterAuthSubpaths = ['client', 'react', 'vue', 'svelte', 'solid'];
const resolvedAliases = betterAuthSubpaths.flatMap((sub) => {
try {
return [{ find: `better-auth/${sub}`, replacement: resolveFile(`better-auth/${sub}`) }];
} catch {
return [];
}
});
A string find matches the exact id and any id that starts with find + '/', replacing the prefix. resolveFile('better-auth/client') is …/dist/client/index.mjs, so better-auth/client/plugins becomes …/dist/client/index.mjs/plugins.
Possible fix
Anchor the patterns so they only match the exact specifier, and pre-resolve client/plugins too if it should avoid the lazy-discovery reload the comment mentions:
const betterAuthSubpaths = ['client', 'client/plugins', 'react', 'vue', 'svelte', 'solid'];
// …
return [{ find: new RegExp(`^better-auth/${sub}$`), replacement: resolveFile(`better-auth/${sub}`) }];
Workaround
A plugin listed after voidPlugin() adds an exact-match alias. Aliases from a later plugin's config hook are tried first, so this one wins:
// vite.config.ts
import { createRequire } from 'node:module';
import type { Plugin } from 'vite-plus';
const require = createRequire(import.meta.url);
function betterAuthClientPlugins(): Plugin {
return {
name: 'better-auth-client-plugins',
config: () => ({
resolve: {
alias: [
{
find: /^better-auth\/client\/plugins$/,
replacement: require.resolve('better-auth/client/plugins'),
},
],
},
}),
};
}
// plugins: [voidPlugin(), voidReact(), betterAuthClientPlugins()]
Related
#554 edits the same block (adds authConfigEnvironmentConfig to the returned config) but keeps the prefix aliases.
Environment
- void 1.2.1 (also on 1.1.12), better-auth 1.7.11
- vite-plus 1.3.0, Node 22.23.3, macOS 26.6
- 主要语言
- TypeScript
- 星标
- 402
- 派生
- 32
- 平均合并
- 8 小时 32 分钟
- 30 天内合并 PR
- 111
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
voidzero-dev/void 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
voidzero-dev/void#529 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1-3 小时 新手友好度 78/100
voidzero-dev/void#428 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 53/100
voidzero-dev/void#567 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
voidzero-dev/void#564 ·
维护者通常 1 天内回复
-
Navigation commit failure leaves the loading state active and causes inconsistent internal state未关闭
难度 4/5 3-5 天 新手友好度 48/100
voidzero-dev/void#562 ·
维护者通常 1 天内回复
查看 voidzero-dev/void 的全部 Issue
相似的 Issue
-
bug hacktoberfest help wanted
难度 2/5 1-3 小时 新手友好度 82/100
libredb/libredb-studio#1941 ·
维护者通常 1 天内回复
-
chore other
难度 2/5 1-3 小时 新手友好度 78/100
alastair-smith/card-games#308 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 86/100
paperclipai/paperclip#17379 ·
维护者通常 1 天内回复
-
[good first issue, hacktoberfest] 🏯 Hacktoberfest Task - Add new Anime Quote 626 (good-first-issue)未关闭community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
难度 1/5 1 小时以内 新手友好度 76/100
lingdojo/kana-dojo#33040 · 1 条评论 · 5 个 reaction ·
维护者通常 1 天内回复
-
bug mobile ui
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复