Ad Space — Top Banner

TS2307

TypeScript Programming Language

Severity: Moderate

What Does This Error Mean?

TypeScript cannot locate the module you imported. Either the package is not installed, the path is wrong, or type declarations are missing. Installing the package or its @types definition usually fixes it.

Affected Models

  • TypeScript 5.x
  • TypeScript 4.x
  • React + TypeScript
  • Node.js + TypeScript

Common Causes

  • The npm package is not installed — forgot to run npm install
  • The import path is wrong — a typo or incorrect relative path
  • The package exists but has no TypeScript type declarations
  • The @types/package is missing from devDependencies
  • The tsconfig.json paths or baseUrl is misconfigured

How to Fix It

  1. Check the package is installed: run npm list <package-name>.

    If it is not listed, run npm install <package-name> to add it.

  2. If the package is a JavaScript library, install its type declarations.

    Run npm install --save-dev @types/<package-name>. Example: npm install --save-dev @types/lodash.

  3. Double-check the import path for relative imports.

    Paths like './utils' must match the actual file location. TypeScript is case-sensitive on Linux/Mac.

  4. If the package has no @types, add a declaration file to your project.

    Create a file like src/types/<package-name>.d.ts and add: declare module '<package-name>';

  5. Check your tsconfig.json for baseUrl and paths settings.

    If you use path aliases like @/components, make sure they are mapped correctly in both tsconfig.json and your bundler config.

When to Call a Professional

This error is safe to fix yourself in most cases. If it appears inside a monorepo or complex build pipeline, a senior dev familiar with your toolchain can help.

Frequently Asked Questions

Why does the module work in JavaScript but not TypeScript?

JavaScript does not check types, so missing declarations are invisible. TypeScript requires type information for every import. Installing the @types package gives TypeScript what it needs.

What if there is no @types package for the library I am using?

You can write a minimal declaration file yourself. Create a .d.ts file and add: declare module 'library-name'; This silences the error, though you lose type checking for that module.

Can I just disable this error globally?

You can, but it is not recommended. Setting noImplicitAny: false or using @ts-ignore hides real problems. Fixing the root cause gives you better safety and autocomplete.