[GH-ISSUE #7004] Importing from better-auth/plugins/organization breaks the CLI #10698

Closed
opened 2026-04-13 06:59:24 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @mhamid3d on GitHub (Dec 26, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7004

Originally assigned to: @bytaesu on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Import defaultStatements or adminAc from better-auth/plugins/organization anywhere in your auth.ts file
  2. Run npx @better-auth/cli generate
  3. See the import error

Current vs. Expected behavior

I expect the import to work with CLI since it works in the node runtime

What version of Better Auth are you using?

1.4.9

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { createAccessControl, organization } from "better-auth/plugins";
import { adminAc, defaultStatements, memberAc, ownerAc } from "better-auth/plugins/organization";
import { drizzle } from "drizzle-orm/node-postgres";
import pg from "pg";

const statement = {
	...defaultStatements,
	project: ["create", "update", "delete"],
} as const;

export const ac = createAccessControl(statement);

export const owner = ac.newRole({
	...ownerAc.statements,
	project: ["create", "delete", "update"],
});

export const admin = ac.newRole({
	...adminAc.statements,
	project: ["create", "delete", "update"],
});

export const member = ac.newRole({
	...memberAc.statements,
	project: [],
});

export const roles = {
	member,
	admin,
	owner,
};

const db = drizzle(new pg.Pool());

export const auth = betterAuth({
	database: drizzleAdapter(db, {
		provider: "pg",
		schema: {},
	}),
	//
	plugins: [
		organization({
			teams: {
				enabled: true,
				allowRemovingAllTeams: true,
			},
			requireEmailVerificationOnInvitation: true,
			ac,
			roles,
			dynamicAccessControl: {
				enabled: true,
			},
		}),
	],
});

Additional context

No response

Originally created by @mhamid3d on GitHub (Dec 26, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7004 Originally assigned to: @bytaesu on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Import `defaultStatements` or `adminAc` from `better-auth/plugins/organization` anywhere in your `auth.ts` file 2. Run `npx @better-auth/cli generate` 3. See the import error ### Current vs. Expected behavior I expect the import to work with CLI since it works in the node runtime ### What version of Better Auth are you using? 1.4.9 ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { createAccessControl, organization } from "better-auth/plugins"; import { adminAc, defaultStatements, memberAc, ownerAc } from "better-auth/plugins/organization"; import { drizzle } from "drizzle-orm/node-postgres"; import pg from "pg"; const statement = { ...defaultStatements, project: ["create", "update", "delete"], } as const; export const ac = createAccessControl(statement); export const owner = ac.newRole({ ...ownerAc.statements, project: ["create", "delete", "update"], }); export const admin = ac.newRole({ ...adminAc.statements, project: ["create", "delete", "update"], }); export const member = ac.newRole({ ...memberAc.statements, project: [], }); export const roles = { member, admin, owner, }; const db = drizzle(new pg.Pool()); export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema: {}, }), // plugins: [ organization({ teams: { enabled: true, allowRemovingAllTeams: true, }, requireEmailVerificationOnInvitation: true, ac, roles, dynamicAccessControl: { enabled: true, }, }), ], }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 06:59:24 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 26, 2025):

It looks like you're encountering an issue with importing from better-auth/plugins/organization, which leads to a CLI error when you run npx @better-auth/cli generate. This might be due to the CLI not resolving the imported modules properly.

One recommended troubleshooting step is to avoid using import aliases in your configuration file and instead use relative paths. After running the CLI command, you can revert to using aliases if needed. This adjustment may help the CLI to correctly recognize the modules you are trying to import [2].

If this doesn't solve the issue or if you need further assistance, I encourage you to tag @bekacru or @ping__ for more help directly from the team. Would you like to explore anything specific about Better Auth or its configuration?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3692715034 --> @better-auth-agent[bot] commented on GitHub (Dec 26, 2025): It looks like you're encountering an issue with importing from `better-auth/plugins/organization`, which leads to a CLI error when you run `npx @better-auth/cli generate`. This might be due to the CLI not resolving the imported modules properly. One recommended troubleshooting step is to avoid using import aliases in your configuration file and instead use relative paths. After running the CLI command, you can revert to using aliases if needed. This adjustment may help the CLI to correctly recognize the modules you are trying to import [[2]](https://www.better-auth.com/docs/concepts/cli). If this doesn't solve the issue or if you need further assistance, I encourage you to tag @bekacru or @ping__ for more help directly from the team. Would you like to explore anything specific about Better Auth or its configuration? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 26, 2025):

This happens because better-auth/plugins/organization does not export defaultStatements, adminAc, ownerAc, or memberAc as runtime values—those are only available from the subpath better-auth/plugins/organization/access. The CLI uses a stricter module resolution than Node, so it can't find these exports at the top-level plugin path, even if your bundler resolves them in development.

To fix the CLI import error, update your imports like this:

import { defaultStatements, adminAc, memberAc, ownerAc } from "better-auth/plugins/organization/access";

Also, when defining roles, spread the permission objects directly—don't reference .statements properties, which don't exist on these role objects. For example:

export const owner = ac.newRole({
  ...ownerAc,
  project: ["create", "delete", "update"],
});

export const admin = ac.newRole({
  ...adminAc,
  project: ["create", "delete", "update"],
});

export const member = ac.newRole({
  ...memberAc,
  project: [],
});

This is a known issue with the CLI and plugin exports—see this GitHub thread for details and confirmation. Using the correct subpath for imports resolves the CLI error.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3692721881 --> @dosubot[bot] commented on GitHub (Dec 26, 2025): <!-- Answer --> This happens because `better-auth/plugins/organization` does not export `defaultStatements`, `adminAc`, `ownerAc`, or `memberAc` as runtime values—those are only available from the subpath `better-auth/plugins/organization/access`. The CLI uses a stricter module resolution than Node, so it can't find these exports at the top-level plugin path, even if your bundler resolves them in development. To fix the CLI import error, update your imports like this: ```ts import { defaultStatements, adminAc, memberAc, ownerAc } from "better-auth/plugins/organization/access"; ``` Also, when defining roles, spread the permission objects directly—don't reference `.statements` properties, which don't exist on these role objects. For example: ```ts export const owner = ac.newRole({ ...ownerAc, project: ["create", "delete", "update"], }); export const admin = ac.newRole({ ...adminAc, project: ["create", "delete", "update"], }); export const member = ac.newRole({ ...memberAc, project: [], }); ``` This is a known issue with the CLI and plugin exports—see [this GitHub thread for details and confirmation](https://github.com/better-auth/better-auth/issues/3472). Using the correct subpath for imports resolves the CLI error. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/39a95fa9-789e-4a58-8b9f-f95d3d62e0b9?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/39a95fa9-789e-4a58-8b9f-f95d3d62e0b9?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/39a95fa9-789e-4a58-8b9f-f95d3d62e0b9?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/39a95fa9-789e-4a58-8b9f-f95d3d62e0b9?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/39a95fa9-789e-4a58-8b9f-f95d3d62e0b9?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/39a95fa9-789e-4a58-8b9f-f95d3d62e0b9?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/39a95fa9-789e-4a58-8b9f-f95d3d62e0b9?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20happens%20because%20%60better-auth/plugins/organization%60%20does%20not%20export%20%60defaultStatements%60%2C%20%60adminAc%60%2C%20%60ownerAc%60%2C%20or%20%60memberAc%60%20as%20runtime%20values%E2%80%94those%20are%20only%20available%20from%20the%20subpath%20%60better-auth/plugins/organization/access%60.%20The%20CLI%20uses%20a%20stricter%20module%20resolution%20than%20Node%2C%20so%20it%20can%27t%20find%20these%20exports%20at%20the%20top-level%20plugin%20path%2C%20even%20if%20your%20bundler%20resolves%20them%20in%20development.%20%0A%0ATo%20fix%20the%20CLI%20import%20error%2C%20update%20your%20imports%20like%20this%3A%0A%0A%60%60%60ts%0Aimport%20%7B%20defaultStatements%2C%20adminAc%2C%20memberAc%2C%20ownerAc%20%7D%20from%20%22better-auth/plugins/organization/access%22%3B%0A%60%60%60%0A%0AAlso%2C%20when%20defining%20roles%2C%20spread%20the%20permission%20objects%20directly%E2%80%94don%27t%20reference%20%60.statements%60%20properties%2C%20which%20don%27t%20exist%20on%20these%20role%20objects.%20For%20example%3A%0A%0A%60%60%60ts%0Aexport%20const%20owner%20%3D%20ac.newRole%28%7B%0A%20%20...ownerAc%2C%0A%20%20project%3A%20%5B%22create%22%2C%20%22delete%22%2C%20%22update%22%5D%2C%0A%7D%29%3B%0A%0Aexport%20const%20admin%20%3D%20ac.newRole%28%7B%0A%20%20...adminAc%2C%0A%20%20project%3A%20%5B%22create%22%2C%20%22delete%22%2C%20%22update%22%5D%2C%0A%7D%29%3B%0A%0Aexport%20const%20member%20%3D%20ac.newRole%28%7B%0A%20%20...memberAc%2C%0A%20%20project%3A%20%5B%5D%2C%0A%7D%29%3B%0A%60%60%60%0A%0AThis%20is%20a%20known%20issue%20with%20the%20CLI%20and%20plugin%20exports%E2%80%94see%20%5Bthis%20GitHub%20thread%20for%20details%20and%20confirmation%5D%28https%3A//github.com/better-auth/better-auth/issues/3472%29.%20Using%20the%20correct%20subpath%20for%20imports%20resolves%20the%20CLI%20error.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7004)
Author
Owner

@bytaesu commented on GitHub (Dec 26, 2025):

Hi @mhamid3d,

Could you try importing it using this path? It seems the types were incorrectly re-exported from better-auth/plugins/organization, I'll fix this. For more information, you can check here!

import {
	adminAc,
	defaultStatements,
	memberAc,
	ownerAc,
} from "better-auth/plugins/organization/access";
<!-- gh-comment-id:3693460455 --> @bytaesu commented on GitHub (Dec 26, 2025): Hi @mhamid3d, Could you try importing it using this path? It seems the types were incorrectly re-exported from `better-auth/plugins/organization`, I'll fix this. For more information, you can check [here](https://www.better-auth.com/docs/plugins/organization#custom-permissions)! ```ts import { adminAc, defaultStatements, memberAc, ownerAc, } from "better-auth/plugins/organization/access"; ```
Author
Owner

@mhamid3d commented on GitHub (Dec 26, 2025):

@bytaesu That fixes the issue. My IntelliSense must've suggested the shortest possible import

<!-- gh-comment-id:3693481582 --> @mhamid3d commented on GitHub (Dec 26, 2025): @bytaesu That fixes the issue. My IntelliSense must've suggested the shortest possible import
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10698