# error TS2307: Cannot find module TypeScript fails the build.

URL: https://antideploy.com/blog/typescript-error-fails-the-build

A production build checks types. A type error stops it, even if the app runs in dev mode. Run the type check on your machine and fix what it reports.

**What you see**

```
src/app/page.tsx:12:20
error TS2307: Cannot find module '@/lib/db' or its corresponding type
declarations.
Type error: Cannot find module '@/lib/db' or its corresponding type
declarations.
```

## At a glance

- **What it means**: The type check found an error
- **Test it locally**: Run npx tsc --noEmit
- **The fix**: Fix each reported error
- **Why dev works**: Dev mode does not check everything

Published 7 October 2026. Facts checked 7 October 2026. 1 min read.

## What it means

TypeScript checks your code for mistakes before it is built. In development, tools like `next dev` and `vite dev` skip or soften that check, so the app can run with errors. A production build treats type errors as failures. The build says the same: type errors fail the build even when the app runs locally with `next dev`.

## How to fix it

### 1. Run the type check on your machine

Run `npx tsc --noEmit`. It lists every type error with its file and line, without building anything.

### 2. Fix each error

Ask your agent: "Fix all TypeScript errors that `npx tsc --noEmit` reports." Fix the cause, not the symptom.

### 3. Run the production build locally

Run `npm run build`. When it passes locally, deploy again. A failed deploy never counts against your plan.

## Errors you will often see

- **TS2307, Cannot find module.** A path alias such as `@/lib/db` is not set in `tsconfig.json`, the file does not exist, or a `@types` package is missing.
- **TS7006, implicit any.** A parameter has no type and `strict` mode is on.
- **TS6133, declared but never used.** A variable or import is unused and `noUnusedLocals` is on.
- **TS2322, type not assignable.** A value does not match the type it is given.

## TypeScript questions, answered.

Anything else? Write to us and a person answers.

[support@antideploy.com](mailto:support@antideploy.com)

### Can I turn the type check off?

Some tools let you ignore build errors, for example `ignoreBuildErrors` in the Next.js config. That ships the errors to production, so it is better to fix them.

### Why does it work with next dev?

Development mode compiles pages as you open them and does not fail on every type error.

### Does this failed deploy cost anything?

No. Failed deploys never count against your plan.

## More guides, and the platform.

Each platform page covers one part of Antideploy: what it does, where it stops and the questions people ask. [See the whole platform](https://antideploy.com/platform), or [all the guides](https://antideploy.com/blog).

- [Failed to collect page data for /api/users](https://antideploy.com/blog/nextjs-failed-to-collect-page-data): A route's code threw during the build. Usually a variable or a database call at the top of a file.
- [Module not found: Can't resolve](https://antideploy.com/blog/module-not-found-cant-resolve): The build cannot find an import. Match capital letters exactly, add the package, or commit the file.
- [How to deploy a Next.js app with a backend and database](https://antideploy.com/blog/how-to-deploy-a-nextjs-app-with-a-backend-and-database): API routes, Postgres and Prisma. What runs, how migrations work, and why builds fail on environment variables.

- [Deployments](https://antideploy.com/platform/deployments)
- [Logs and monitoring](https://antideploy.com/platform/logs-and-monitoring)

Facts on this page were checked against the live platform on 7 October 2026.

## Deploy something. Start with one sentence.

Paste one sentence into your coding agent, click Approve once, and get a live link. No card, no trial clock.

To set this up, give your coding agent this sentence:

```text
Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.
```
