Declaration File .d.ts Missing Error — Fix (2026)

The Error

error TS7016: Could not find a declaration file for module 'some-library'.
  '/node_modules/some-library/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/some-library` if it exists or add a new declaration (.d.ts) file.

This error occurs when TypeScript cannot find type declarations for an imported JavaScript library. The library works at runtime but TypeScript cannot type-check it.

The Fix

  1. Try installing the community types package:
npm install --save-dev @types/some-library
  1. If no @types package exists, create a declaration file:
mkdir -p src/types
// src/types/some-library.d.ts
declare module 'some-library' {
  export function doSomething(input: string): Promise<string>;
  export default function init(config: Record<string, unknown>): void;
}
  1. Ensure tsconfig includes the types directory:
{
  "compilerOptions": {
    "typeRoots": ["./node_modules/@types", "./src/types"]
  }
}
  1. Verify:
npx tsc --noEmit

Why This Happens

Many npm packages are written in JavaScript without TypeScript declarations. TypeScript needs .d.ts files to understand the types of imported modules. When Claude adds a dependency that lacks types, the compiler throws TS7016. The @types/ namespace on npm hosts community-maintained declarations, but not every package has one.

If That Doesn’t Work

  • Suppress the error for a single import:
// @ts-ignore
import something from 'untyped-library';
  • Set noImplicitAny: false in tsconfig (not recommended for strict projects).
  • Use skipLibCheck: true to skip checking all .d.ts files:
{
  "compilerOptions": { "skipLibCheck": true }
}

Prevention

Add this to your CLAUDE.md:

# TypeScript Declarations
- After adding a new dependency, check: npm info @types/PACKAGE
- If no @types exists, create src/types/PACKAGE.d.ts with at least basic types.
- Keep typeRoots in tsconfig pointing to both node_modules/@types and src/types.

See Also

This fix also applies if you see these related error messages:

  • npm ERR! code EACCES
  • npm ERR! code ERESOLVE
  • npm ERR! peer dep missing
  • Error: Claude Code requires Node.js 18 or later
  • SyntaxError: Unexpected token '??' — Node 14 detected

Frequently Asked Questions

Should I use npm or pnpm with Claude Code?

Claude Code works with any Node.js package manager. If your project uses pnpm, add Use pnpm instead of npm for all package operations to your CLAUDE.md so Claude Code respects your toolchain choice.

Why does Claude Code sometimes run npm commands that fail?

Claude Code infers the package manager from lock files. If both package-lock.json and pnpm-lock.yaml exist, it may pick the wrong one. Delete the unused lock file or add an explicit instruction in CLAUDE.md.

How do I verify my npm installation is working?

Run npm doctor to check your npm environment. It validates the registry connection, permissions, cache integrity, and Node.js compatibility in one command.

What Node.js version does Claude Code require?

Claude Code requires Node.js 18 or later. Node.js 20 LTS is recommended for the best compatibility and performance. Check your version with node --version.

Try it: Paste your error into our Error Diagnostic for an instant fix.

Implementation Details

When working with this in Claude Code, pay attention to these practical details:

Project configuration. Add specific instructions to your CLAUDE.md file describing how your project handles this area. Include file paths, naming conventions, and any patterns that differ from common defaults. Claude Code reads CLAUDE.md at the start of every session and uses it to guide all operations.

Testing the setup. After configuration, verify everything works by running a simple test task. Ask Claude Code to perform a read-only operation first (like listing files or reading a config) before moving to write operations. This confirms that permissions, paths, and tools are all correctly configured.

Monitoring and iteration. Track your results over several sessions. If Claude Code consistently makes the same mistake, the fix is usually a more specific CLAUDE.md instruction. If it makes different mistakes each time, the issue is likely in the project setup or toolchain configuration.

Troubleshooting Checklist

When something does not work as expected, check these items in order:

  1. CLAUDE.md exists at the project root — run ls -la CLAUDE.md to verify
  2. Node.js version is 18+ — run node --version to check
  3. API key is set — run echo $ANTHROPIC_API_KEY | head -c 10 to verify (shows first 10 characters only)
  4. Disk space is available — run df -h . to check
  5. Network can reach the API — run curl -s -o /dev/null -w "%{http_code}" https://api.anthropic.com (should return 401 without auth, meaning the server is reachable)
  6. No conflicting processes — run ps aux | grep claude | grep -v grep to check for stale sessions