i have the following file (I intend to use the .js file generated in node):
import { someFunction } from './otherfile.ts';
how do i compile this? the tsc command doesn't work because my tsconfig.json is:
{
"compilerOptions": {
"allowImportingTsExtensions": true,
"noEmit": true,
"strict": true
}
}
(to be able to use allowImportingTsExtensions I need noEmit)
This is a weird fix but it works, just change the import to ".js" even if its a ts file. You won't need to change your tsconfig for this.
This error happens because you've specified moduleResolution: NodeNext. This tells TypeScript that you want your imports and exports to conform strictly to the Node spec. The Node spec requires that you use .js file extensions for all imports and exports. This was decided so that a relative import path like ./foo.js would work both in Node and the browser.
Matt Pocock explains the reasoning nicely here https://www.totaltypescript.com/relative-import-paths-need-explicit-file-extensions-in-ecmascript-imports