Trouble with absolute imports
I have paths set in my tsconfig like so
"compilerOptions": {
"paths": {
"~app/*": ["src/*"]
}
},
But when I try to run ts-node-test, I get
Error: Cannot find package '~app' imported from <path>
Does ts-node-test look at compilerOptions.paths ?
It doesn't, and I think it doesn't need to since it doesn't handle imports at all. This is the responsibility of Node.js + ts-node. ts-node-test only recursively resolves the list of test files and calls node --test --loader=ts-node/esm with that list. What happens when you run your test file with ts-node --esm test/my-test-file.test.ts?
$ TEST_EXTENSIONS=.spec.ts ts-node --esm ./utils.spec.ts
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for <path>
Unfortunately I don't know what causes this, but I'm pretty sure it has nothing to do with ts-node-test. It's likely some CommonJS/ESM weirdness and/or missing or invalid configuration of ts-node. It's also entirely possible that Node.js's --test flag messes with the ts-node loader, since --test spawns child processes.