I'm using ts-node and in tsconfig.json
I have "baseUrl": "./src"
. This way I can import a sibling in src
without using ./
. However ts-node does not seem to using the baseUrl
property in resolving the sibling imports, so I get errors like this:
> [email protected] test /home/ole/Junk/tsmochanyc
> mocha -r ts-node/register src/**/*.spec.ts
Error: Cannot find module 'hello'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
Curious whether this is a ts-node bug or whether I should be doing something different?
I'm using ts-node and in tsconfig.json
I have "baseUrl": "./src"
. This way I can import a sibling in src
without using ./
. However ts-node does not seem to using the baseUrl
property in resolving the sibling imports, so I get errors like this:
> [email protected] test /home/ole/Junk/tsmochanyc
> mocha -r ts-node/register src/**/*.spec.ts
Error: Cannot find module 'hello'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
Curious whether this is a ts-node bug or whether I should be doing something different?
Share Improve this question asked Jun 21, 2018 at 0:24 OleOle 47.4k70 gold badges237 silver badges445 bronze badges 1- github./TypeStrong/ts-node/issues/613 – Ole Commented Jun 21, 2018 at 2:42
1 Answer
Reset to default 10As indicated in the issue posted to ts-node tsconfig-paths can be used for this. I have a fully (But minimal) working example here. If you want to try it out just:
git clone https://github./oleersoy/tsmochanyc
cd tsmochanyc
npm i
npm test
Look at the the baseUrl
and paths
propertis in tsconfig.json
to see how the resolution works. In this case they have been set so that tsmochanyc
proxies src/
this way the path mirrors the same paths that devs would use if tsmochanyc
were an external dependency.