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
- Try installing the community types package:
npm install --save-dev @types/some-library
- 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;
}
- Ensure tsconfig includes the types directory:
{
"compilerOptions": {
"typeRoots": ["./node_modules/@types", "./src/types"]
}
}
- 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: falsein tsconfig (not recommended for strict projects). - Use
skipLibCheck: trueto 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
Related Error Messages
This fix also applies if you see these related error messages:
npm ERR! code EACCESnpm ERR! code ERESOLVEnpm ERR! peer dep missingError: Claude Code requires Node.js 18 or laterSyntaxError: 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.
Related Guides
Try it: Paste your error into our Error Diagnostic for an instant fix.
- Terminal Emulator Rendering Artifacts — Fix (2026)
- How to Use Thirdweb SDK Workflow (2026)
- Python Virtualenv Not Activated — Fix (2026)
- Claude Code Offline Mode Setup (2026)
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:
- CLAUDE.md exists at the project root — run
ls -la CLAUDE.mdto verify - Node.js version is 18+ — run
node --versionto check - API key is set — run
echo $ANTHROPIC_API_KEY | head -c 10to verify (shows first 10 characters only) - Disk space is available — run
df -h .to check - 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) - No conflicting processes — run
ps aux | grep claude | grep -v grepto check for stale sessions