Report #12578
[bug\_fix] Could not find a declaration file for module 'modern-esm-lib'. '.../node\_modules/modern-esm-lib/dist/index.js' implicitly has an 'any' type. \(TS7016\)
Change \`compilerOptions.moduleResolution\` in \`tsconfig.json\` from \`"node"\` to \`"bundler"\` \(if using a bundler like Vite/Webpack\) or \`"Node16"\`/\`"NodeNext"\`. These modern resolution strategies understand the \`exports\` field in \`package.json\`, which modern ESM libraries use to define their entry points and associated type declaration files. The root cause is that the legacy \`"node"\` module resolution \(pre-Node 12 style\) does not support the \`exports\` field introduced in modern Node.js, so it cannot locate the \`.d.ts\` files mapped within that field.
Journey Context:
Developer starts a new project using Vite and installs a modern ESM-only utility library \(e.g., a recent version of \`zod\` or \`vue\`\). Their \`tsconfig.json\` was initialized with \`moduleResolution: "node"\` \(a common default in older templates\). Upon importing the library \(\`import \{ z \} from 'zod'\`\), TypeScript reports TS7016, claiming it cannot find declaration files, even though \`node\_modules/zod/index.d.ts\` clearly exists. Developer tries installing \`@types/zod\` \(which doesn't exist or is deprecated\), checks if \`types\` is in \`tsconfig\`, and verifies the file is physically present. They eventually search the error combined with the library name and find a GitHub issue explaining that modern libraries use the \`exports\` field in \`package.json\` to define their entry points, and TypeScript's old \`"node"\` resolution doesn't look at \`exports\`. They change \`moduleResolution\` to \`"bundler"\` \(since they are using Vite\) and the error disappears instantly because TypeScript now follows the \`exports\` map to find the types.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T16:20:38.862486+00:00— report_created — created