-
-
Couldn't load subscription status.
- Fork 209
Description
π₯ Build Error in Web App Due to Cross-Package @/ Alias
π§ͺ Reproduction Steps
Using the default Better-T Stack CLI:
Creating a new Better-T Stack project
β Project name: test-better-t-stack
β Platform: Web
β Web framework: Next.js
β Backend: Next.js
β Database: MySQL
β ORM: Drizzle
β API type: tRPC
β Add authentication: Yes (Better-Auth)
β Addons: Turborepo
β Include examples: none
β Initialize git repo: No
β Package manager: pnpm
β Install dependencies: Yes
The project was scaffolded and dependencies installed successfully.
π§± Setup
Inside the apps/server app, I have a constant being imported via an alias:
// apps/server/src/routers/index.ts
import { DEFAULT_LIMIT } from "@/constants";
import { protectedProcedure, publicProcedure, router } from "../lib/trpc";
export const appRouter = router({
healthCheck: publicProcedure.query(() => {
console.log("healthCheck", DEFAULT_LIMIT);
return "OK";
}),
privateData: protectedProcedure.query(({ ctx }) => {
return {
message: "This is private",
user: ctx.session.user,
};
}),
});
export type AppRouter = typeof appRouter;Then, in the web app, I import the type like this:
// apps/web/src/utils.ts
import type { AppRouter } from "../../../server/src/routers";
𧨠The Problem
When I run pnpm build for the web app, I get the following error:
..../server/src/routers/index.ts:1:31
Type error: Cannot find module '@/constants' or its corresponding type declarations.
This happens because the alias @/constants only exists in the context of the server app. But since I'm importing server source directly into the web app, the @ alias is no longer valid.
βMy Question
I understand why this is happeningβit's due to the alias resolution breaking across app boundaries when importing server code directly from web.
But what are the recommended solutions within the Better-T Stack / Turborepo setup?
I know one solution is to make server its own package, then import from that package inside web
Are there other recommended ways to structure this? Is alias isolation across apps a known concern with the default template?
Would love some insight or guidance on best practices here. Thanks!