Skip to content

Build error on relative import with default templateΒ #333

@teo-goulois

Description

@teo-goulois

πŸ’₯ 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions