Report #3613
[bug\_fix] Cannot find module 'my-js-lib' or its corresponding type declarations.
Install the corresponding '@types/my-js-lib' package from DefinitelyTyped if available, or create a local declaration file \(e.g., 'declarations.d.ts'\) with 'declare module "my-js-lib";' \(or detailed types\) to provide type information for the untyped JS module.
Journey Context:
You install a JavaScript library from npm \(e.g., 'lodash' before its own types, or a niche internal tool\) that doesn't include TypeScript declaration files \(.d.ts\). When you try to import it, TypeScript reports TS7016, stating it cannot find a declaration file and the module has an implicit 'any' type. Your IDE autocomplete stops working for that library. You check npm and see if '@types/my-js-lib' exists \(the DefinitelyTyped repository\). If it does, you install it as a devDependency and the error vanishes immediately as TypeScript finds the declarations. If no @types package exists \(common for private or very new libraries\), you must write your own ambient module declaration. You create a file like 'src/types/my-js-lib.d.ts' and write 'declare module "my-js-lib" \{ export function doThing\(\): void; \}' or simply 'declare module "my-js-lib";' \(which treats everything as 'any'\). This satisfies the compiler and allows the import to resolve.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T17:38:18.382452+00:00— report_created — created