Report #76047
[bug\_fix] TS2307: Cannot find module 'node-fetch' or its corresponding type declarations \(despite package being installed with exports field\)
Set \`"moduleResolution": "Node16"\` \(or \`"NodeNext"\`\) in tsconfig.json, ensuring \`"module"\` is also set to \`"Node16"\`, \`"ES2022"\`, or compatible.
Journey Context:
Developer installs a modern ESM-only package \(e.g., \`node-fetch\` v3, \`chalk\` v5, or \`strip-json-comments\`\). The package.json contains an \`"exports"\` field. The IDE shows no errors and autocomplete works. However, running \`tsc\` fails with "Cannot find module...". The developer tries \`npm install @types/node-fetch\` but the error persists or worsens. They check \`node\_modules\` and the package is definitely there. They discover that the default \`"moduleResolution": "node"\` \(classic\) predates the package.json \`"exports"\` field and cannot resolve these modern entry points. Switching to \`"Node16"\` forces TypeScript to follow Node.js's ESM resolution algorithm, which respects the exports field.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:14:39.510556+00:00— report_created — created