Next.js Discord

Discord Forum

Module not found when using TS path aliases in a monorepo

Unanswered
African Slender-snouted Crocodil… posted this in #help-forum
Open in Discord
African Slender-snouted CrocodileOP
HI, I have a project set up in a monorepo
apps/web -> nextjs project, tsconfig configured with ~/* -> src/*
packages/ui -> shadcn ui components, tsconfig configured with ~/* -> src/*

When I use components from packages/ui, they work fine in dev mode, but when I try to build my next project, I get errors wherever I use path aliases in my ui project
│ Import trace for requested module:
│ ./src/components/auth/login-form.tsx
│ ./src/app/login/page.tsx
│ 
│ ../../packages/ui/src/components/input.tsx
│ Module not found: Can't resolve '~/lib/utils'

This setup works fine with React Remix and Vite (and the vite-tsconfig-paths plugin).
How can I use typescript path aliases with Nextjs? Shadcn requires them to use the CLI

0 Replies