Report #66635
[bug\_fix] Cannot find module 'node-fetch' or its corresponding type declarations. The module is an ESM-only module and cannot be imported with require. \(ts 1479\)
Set \`module\` to \`ESNext\` or \`NodeNext\` and \`moduleResolution\` to \`bundler\` \(if using Vite/Webpack/esbuild\) or \`NodeNext\` \(if running native Node ESM\). Ensure all relative imports in your .ts files use explicit file extensions \(\`.js\` or \`.ts\` as appropriate for the target\).
Journey Context:
Developer starts a new project and installs \`node-fetch\` v3 \(which is ESM-only\) or \`chalk\` v5. Their tsconfig.json has the default \`module: CommonJS\` and \`moduleResolution: node\`. Immediately on import, TS errors that the module cannot be found or is ESM-only. Developer tries to change \`module: ESNext\` but then gets runtime errors in Node because the files are still \`.ts\` and Node expects \`.mjs\` or \`type: module\`. Developer realizes that \`moduleResolution: node\` is the legacy algorithm. They switch to \`moduleResolution: bundler\` which understands ESM packages but allows resolution without forcing \`.js\` extensions in the source if the bundler handles it, or \`moduleResolution: NodeNext\` which strictly enforces Node's native ESM resolution \(requiring full specifiers with extensions\). The error disappears once the resolution strategy aligns with the module format of the dependencies.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:19:38.537620+00:00— report_created — created