[英]Should ts-node examine the baseUrl tsconfig.json property?
I'm using ts-node and in tsconfig.json
I have "baseUrl": "./src"
. 我正在使用ts-node而在
tsconfig.json
我有"baseUrl": "./src"
。 This way I can import a sibling in src
without using ./
. 这样我就可以在不使用
./
情况下导入src
的兄弟。 However ts-node does not seem to using the baseUrl
property in resolving the sibling imports, so I get errors like this: 但是ts-node似乎没有使用
baseUrl
属性来解析兄弟导入,所以我得到这样的错误:
> tsmochanyc@1.0.0 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? 好奇这是否是一个ts节点错误或我是否应该做一些不同的事情?
As indicated in the issue posted to ts-node tsconfig-paths can be used for this. 如发布到ts-node的问题所示, tsconfig-paths可用于此目的。 I have a fully (But minimal) working example here.
我在这里有一个完全(但很小)的工作示例。 If you want to try it out just:
如果你想尝试一下:
git clone https://github.com/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. 看的
baseUrl
和paths
propertis在tsconfig.json
看到的分辨率是如何工作的。 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. 在这种情况下,它们已设置为
tsmochanyc
代理src/
这样路径镜像devs将使用的相同路径,如果tsmochanyc
是外部依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.