What this error means and why it happens
When you see "Could not find a declaration file for module," your code is looking for a type declaration file — a file that tells your development environment what functions, objects, and data types a piece of code contains — and cannot locate it. This error most often appears in TypeScript projects, though it can show up in JavaScript projects using TypeScript checking.
The error happens because you are trying to use a package or module that either does not have type information included, or the type information exists but your project cannot find where it is stored. Think of a type declaration file as an instruction manual: your code needs to know what tools are available in a package before it can use them safely.
This is not a sign that your code is broken or that the package does not work. It means your development environment cannot verify that you are using the package correctly before you run the code. Many packages work fine at runtime even when this error appears, but fixing it prevents mistakes and makes your code easier to maintain.
Key Takeaways
- Type declaration files tell TypeScript what functions and objects exist in a package; the error means your project cannot find this information.
- The fastest fix is usually to install the @types version of the package from npm, which is a separate package containing only type information.
- If no @types version exists, you can create a minimal declaration file yourself or configure TypeScript to skip type checking for that package.
- This error does not prevent your code from running; it only prevents TypeScript from checking whether you are using the package correctly.
How to find and install the types package
The most common fix is to install a separate package that contains the type declarations. These packages live on npm under the @types namespace and are maintained by the community. If you are using a package called lodash, for example, you would install @types/lodash.
Open your terminal in your project folder and run:
npm install --save-dev @types/package-name
Replace package-name with the actual name of the package causing the error. The --save-dev flag puts it in your development dependencies, since you only need type information while you are writing code, not when the code runs in production.
After installation, reload your code editor. The error should disappear. If it does not, close and reopen the editor completely, as some editors cache type information.
What to do if no @types package exists
Some packages, especially older or less common ones, do not have a @types version available. You have two options: create a minimal declaration file yourself, or tell TypeScript to skip type checking for that package.
The easier option is to skip type checking. Open your tsconfig.json file (the configuration file that controls how TypeScript behaves in your project) and add the package name to the skipLibCheck setting or create a declaration file that tells TypeScript to treat the package as any. Add this line to your tsconfig.json:
"skipLibCheck": true
This tells TypeScript not to check the type information in library files, which silences the error. The downside is that you lose type safety for that package — TypeScript will not warn you if you use it incorrectly.
If you want more control, create a new file in your project called index.d.ts (or name it after the package, like my-package.d.ts) and add:
declare module 'package-name';
This tells TypeScript that the module exists but has no type information, which stops the error without disabling type checking for your entire project.
When the package includes its own type declarations
Some modern packages include type declarations built in. If the error persists even though the package is installed, the problem may be that TypeScript cannot find the declaration file because of how your project is configured.
Check the package's package.json file (usually in node_modules/package-name/package.json) and look for a types or typings field. If it exists, it points to where the type declarations are located. If the path is broken or the file does not exist, the package itself may be damaged or installed incorrectly.
Try deleting your node_modules folder and your lock file (package-lock.json for npm, or yarn.lock for yarn), then reinstalling everything:
rm -rf node_modules package-lock.json npm install
This forces a fresh read of all packages and often resolves corruption or incomplete installations.
Checking your TypeScript configuration
Sometimes the error appears because your tsconfig.json is configured too strictly. Open the file and check the moduleResolution setting. It should be set to node for most projects:
"moduleResolution": "node"
Also check that declaration is not set to true unless you are building a library. If you are building an process, set it to false:
"declaration": false
If you are using a monorepo or a complex project structure, the error may be caused by path mapping issues. Check whether your paths configuration in tsconfig.json is pointing to the correct locations.
Preventing this error in new projects
When you start a new TypeScript project, use a tool like create-react-app, Vite, or Next.js to set up your configuration automatically. These tools configure TypeScript correctly from the start and include sensible defaults for type checking.
If you are setting up TypeScript manually, start with a strict tsconfig.json and relax it only when necessary. A stricter configuration catches more errors early. When you add a new package, check whether a @types version exists before installing it. The npm website and the TypeScript documentation both have searchable lists of available @types packages.
Frequently Asked Questions
Does this error mean my code will not run?
No. This error only affects TypeScript's ability to check your code before it runs. Your code will run fine at runtime, but TypeScript cannot warn you if you use the package incorrectly. It is like driving without a dashboard warning light — the car still works, but you lose early warning of problems.
Can I ignore this error and keep working?
Yes, but it is not recommended. Ignoring it means you lose type safety for that package, which makes it easier to introduce bugs. Spending five minutes to install the @types package or configure TypeScript properly saves debugging time later.
What if I install @types/package-name but the error does not go away?
Reload your code editor completely — close it and open it again. Some editors cache type information. If that does not work, check that the package name in the error message matches the package name you installed. Sometimes the package name in the error is slightly different from the npm package name.
Is it safe to use skipLibCheck?
It is safe in the sense that your code will still run, but it disables type checking for all library files, not just the one causing the error. Use it only as a temporary fix while you find a proper solution, or use it for packages you trust completely and do not plan to update often.
Why do some packages not have @types versions?
Older packages were written before TypeScript became common, so they never had types added. Some maintainers choose not to publish types separately. In these cases, creating a minimal declaration file or using skipLibCheck is the only option.