Report #96818
[bug\_fix] Cannot find module '@app/utils' or its corresponding type declarations. ts\(2307\)
Add the \`.js\` file extension to the import path \(e.g., \`import \{ foo \} from '@app/utils.js'\`\) and ensure \`moduleResolution\` is set to \`NodeNext\` or \`Bundler\`. When using path mapping with \`NodeNext\`, TypeScript enforces ESM rules where imports must include explicit file extensions, even for TypeScript source files.
Journey Context:
Developer migrates a project to ESM, setting \`"type": "module"\` in package.json and \`"moduleResolution": "NodeNext"\` in tsconfig.json. They configure path mapping \`"@app/\*": \["./src/\*"\]\` to clean up deep relative imports. In their source, they write \`import \{ util \} from '@app/utils'\`. The IDE resolves it via the path map, but running \`tsc\` throws TS2307. They check \`baseUrl\` and try various relative path adjustments. They realize that with \`NodeNext\`, TypeScript enforces Node.js ESM resolution rules: specifiers must include file extensions \(\`.js\` for \`.ts\` files\) and cannot import directories. The path mapping resolves the location, but the import specifier itself must be valid ESM. Changing the import to \`@app/utils.js\` satisfies both the path mapping and the ESM loader requirements.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T21:05:40.882363+00:00— report_created — created