Skip to content
Latchkey

Next.js tsconfig path alias "@/..." not resolved in CI

Next.js reads compilerOptions.paths and baseUrl from tsconfig.json to resolve aliases like @/. If those are missing, mistyped, or point at a path whose case differs on Linux, the alias fails to resolve during next build.

What this error means

next build fails with "Module not found: Can't resolve '@/components/Button'" while the dev server resolved it, typically because tsconfig paths are absent or the target case differs in CI.

next build
./app/page.tsx
Module not found: Can't resolve '@/components/Button'

https://nextjs.org/docs/messages/module-not-found

Common causes

baseUrl or paths is missing in tsconfig

Next relies on the tsconfig mapping to expand @/; without baseUrl and a paths entry the alias is unresolvable.

The aliased target has a case mismatch on Linux

The alias resolves to a path whose directory or file case differs from the committed name, which only fails on the case-sensitive runner.

How to fix it

Define baseUrl and paths in tsconfig

  1. Set baseUrl and add a paths mapping for the alias prefix.
  2. Confirm the target case matches the committed file names.
  3. Re-run next build.
tsconfig.json
// tsconfig.json
{ "compilerOptions": {
    "baseUrl": ".",
    "paths": { "@/*": ["./*"] }
} }

Fix any case mismatch in the resolved path

Make the alias target match the committed casing exactly so the Linux runner resolves it.

How to prevent it

  • Keep tsconfig paths and baseUrl in sync with your alias usage.
  • Match import case to committed file names for Linux CI.
  • Run a Linux build before merge to catch alias and case issues.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →