Report #5921
[bug\_fix] Cannot find module '\#utils' or its corresponding type declarations when using Node.js subpath imports
Set \`moduleResolution\` to \`nodenext\` or \`node16\` in \`tsconfig.json\`. The root cause is that subpath imports \(defined in \`package.json\` under \`imports\`\) are only resolved by TypeScript when using the Node.js-native resolution algorithms introduced in TS 4.7, not the legacy \`node\` resolution.
Journey Context:
You are modernizing a Node.js app to ESM. You define subpath imports in \`package.json\`: \`"imports": \{ "\#config/\*": "./dist/config/\*.js" \}\`. You use \`import \{ db \} from '\#config/database'\` in your TS file. Node runs it perfectly, but VS Code shows 'Cannot find module'. You try adding a \`paths\` mapping in tsconfig, but it feels redundant and doesn't work for subpath imports. You check the TS 4.7 release notes and discover \`moduleResolution: nodenext\`. You change it from \`node\`, and immediately the \`\#\` imports resolve correctly because TS now reads the \`imports\` field from \`package.json\` using Node's own resolution rules.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:40:29.007113+00:00— report_created — created