In package.json I have "type": "module" and I use SWC to compile the typescript code. When doing imports I use import Example from './example' and then use "start": "node --es-module-specifier-resolution=node lib/index.js" as a script so that I don't have to specify the extensions. This allows me to compile using SWC without needing to specify the extensions which is amazing, otherwise I have to specify .js extensions, inside typescript, for when it's compiled to a different /lib directory.
However when running tsc --emitDeclrationOnly on the codebase it breaks with the above error when I have "moduleResolution": "nodenext" in tsconfig.json. It's telling me that nodenext or node16 enforces file extensions. That is quite annoying and sort of makes it difficult to use nodenext or node16. Is there a reason why this is done, or am I missing something that allows me to easily tell typescript how to resolve extensions by itself?
In your tsconfig.json, update the moduleResolution configuration:
"moduleResolution": "bundler",
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With