ts-node
ts-node copied to clipboard
When used with tsconfig-paths, tsconfig-paths should use a ts-node provided tsconfig.json path
Desired Behavior
ts-node can resolve a tsconfig.json file relative to the entrypoint script. This is great. It seems tsconfig-paths will instead try to use the current working directory. This means that when combining both, different tsconfig paths will be resolved if you are relying on auto-discovery and the entrypoint script is not located in the cwd.
Is this request related to a problem?
When using tsconfig-paths, I have to either provide the project param explicitly or only use entrypoint scripts in my cwd.
My current workaround is a wrapper for both libraries:
my-ts-node.ts
#!/usr/bin/env ts-node --transpileOnly
import execa from 'execa';
import * as ts from 'typescript';
const entrypoint = process.argv[2];
const configFile = ts.findConfigFile(entrypoint, ts.sys.fileExists);
const args = process.argv.slice(3);
void (async () => {
await execa(
'/usr/bin/env',
[
'ts-node',
...(configFile
? ['--project', configFile, '--require', 'tsconfig-paths/register']
: []),
entrypoint,
...args,
],
{
stdio: 'inherit',
},
);
})();