Issue with "@" Path Alias in Turborepo Build Causing Module Not Found Error #10270
-
SummaryI'm using a Turborepo monorepo setup where my UI package's import { cn } from '@rhu-ii/ui/lib/utils'the build runs successfully. However, if I change the alias in import { cn } from '@/lib/utils'I get a build error: Here's my {
"extends": "@rhu-ii/typescript/internal-library.json",
"compilerOptions": {
"jsx": "preserve",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src"],
"exclude": ["node_modules"]
}And here's my {
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"outDir": "${configDir}/dist",
"module": "Preserve",
"moduleResolution": "Bundler"
}
}And here's my {
"name": "@rhu-ii/ui",
"version": "0.0.0",
"private": true,
"exports": {
"./lib/*": "./src/lib/*.ts",
"./components/*": "./src/components/*.tsx",
"./hooks/*": "./src/hooks/*.ts"
},
"scripts": {
"ui-add": "bunx --bun shadcn@latest add",
"postui-add": "prettier src --write --list-different",
"lint": "eslint . --max-warnings 0",
"generate:component": "turbo gen react-component",
"check-types": "tsc --noEmit",
"clean": "git clean -xdf .cache .turbo node_modules"
},
"devDependencies": {
"@rhu-ii/eslint": "*",
"@rhu-ii/typescript": "0.0.0",
"@rhu-ii/prettier": "*",
"@rhu-ii/tailwind": "*",
"@turbo/gen": "^2.4.4",
"@types/node": "^22.13.10",
"@types/react": "19.0.12",
"@types/react-dom": "19.0.4",
"eslint": "^9.23.0",
"typescript": "^5.8.2"
},
"dependencies": {
"@hookform/resolvers": "^5.0.1",
"@radix-ui/react-accordion": "^1.2.3",
"@radix-ui/react-alert-dialog": "^1.1.6",
"@radix-ui/react-aspect-ratio": "^1.1.2",
"@radix-ui/react-avatar": "^1.1.3",
"@radix-ui/react-checkbox": "^1.1.4",
"@radix-ui/react-collapsible": "^1.1.3",
"@radix-ui/react-context-menu": "^2.2.6",
"@radix-ui/react-dialog": "^1.1.6",
"@radix-ui/react-dropdown-menu": "^2.1.6",
"@radix-ui/react-hover-card": "^1.1.6",
"@radix-ui/react-label": "^2.1.2",
"@radix-ui/react-menubar": "^1.1.6",
"@radix-ui/react-navigation-menu": "^1.2.5",
"@radix-ui/react-popover": "^1.1.6",
"@radix-ui/react-progress": "^1.1.2",
"@radix-ui/react-radio-group": "^1.2.3",
"@radix-ui/react-scroll-area": "^1.2.3",
"@radix-ui/react-select": "^2.1.6",
"@radix-ui/react-separator": "^1.1.2",
"@radix-ui/react-slider": "^1.2.3",
"@radix-ui/react-slot": "^1.1.2",
"@radix-ui/react-switch": "^1.1.3",
"@radix-ui/react-tabs": "^1.1.3",
"@radix-ui/react-toggle": "^1.1.2",
"@radix-ui/react-toggle-group": "^1.1.2",
"@radix-ui/react-tooltip": "^1.1.8",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"date-fns": "^4.1.0",
"embla-carousel-react": "^8.5.2",
"input-otp": "^1.4.2",
"lucide-react": "^0.487.0",
"next-themes": "^0.4.6",
"react": "^19.1.0",
"react-day-picker": "8.10.1",
"react-dom": "^19.1.0",
"react-hook-form": "^7.55.0",
"react-resizable-panels": "^2.1.7",
"recharts": "^2.15.1",
"sonner": "^2.0.3",
"tailwind-merge": "^3.1.0",
"vaul": "^1.1.2",
"zod": "^3.24.2"
},
"prettier": "@rhu-ii/prettier"
}This error occurs during the Next.js build in the Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Explained here: https://turbo.build/repo/docs/guides/tools/typescript#use-nodejs-subpath-imports-instead-of-typescript-compiler-paths |
Beta Was this translation helpful? Give feedback.
-
|
I came across with this page by having the same issue while trying to build my monorepo react router app in docker. After hours of effort, finding out my problem was never about path resolving, but rather the output of turbo prune. Solution: I fixed it by renaming the |
Beta Was this translation helpful? Give feedback.
Explained here: https://turbo.build/repo/docs/guides/tools/typescript#use-nodejs-subpath-imports-instead-of-typescript-compiler-paths