Report #45084
[bug\_fix] Could not find a declaration file for module 'modern-lib'. '.../node\_modules/modern-lib/dist/index.js' implicitly has an 'any' type. \(TS7016\)
This occurs when consuming a modern npm package that uses the package.json "exports" field to define its entry points and type definitions, but TypeScript is using the legacy moduleResolution: "node" \(Node10\) strategy. The fix is to upgrade TypeScript to 4.7\+ and set moduleResolution to "bundler" \(if using a bundler like Vite/Webpack\) or "node16"/"nodenext" \(if targeting Node.js ESM\). These modern resolution strategies understand the package.json "exports" field and correctly resolve the "types" condition within exports. The root cause is that moduleResolution: "node" follows legacy CommonJS resolution that predates the "exports" field, so it cannot locate type definitions specified only via exports, falling back to implicit any.
Journey Context:
Developer creates a new Vite project \(which uses esbuild\) and installs a modern dependency \(e.g., a recent version of zod, date-fns, or a custom ESM-only library\) that uses package.json "exports" to define entry points: \{"exports": \{ ".": \{ "types": "./dist/index.d.ts", "import": "./dist/index.js" \} \}\}. In src/main.ts, they write import \{ z \} from 'zod'. TypeScript underlines the import with error TS7016: 'Could not find a declaration file for module... implicitly has an 'any' type.' Developer checks node\_modules and confirms the .d.ts file exists at dist/index.d.ts. They try adding "types": \["zod"\] to tsconfig, which fails. They check their tsconfig and see moduleResolution is set to "node" \(the default for many templates\). Researching, they discover that moduleResolution: "node" \(Node10\) was designed before package.json "exports" existed and cannot read the "exports" field to find the "types" condition. They learn TypeScript 4.7 introduced moduleResolution: "node16" and "bundler". Since they're using Vite \(a bundler\), they change moduleResolution to "bundler". Instantly, TypeScript resolves the exports field, finds the .d.ts file, and the error disappears. They understand that modern tooling requires modern TypeScript resolution strategies to support the npm package.json "exports" standard.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:08:32.387064+00:00— report_created — created