Here是显示问题的 Github MCVE。 npm run compile
显示错误。
我正在尝试这样做:
import {Todo} from '@test';
但它没有解决。
src/index.ts:1:20 - error TS2307: Cannot find module '@test'.
我在 tsconfig.json
中有 paths
。
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"paths": {
"@fs/": ["src/"],
"@test/": ["test/"]
}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
想法?
Github typescript 问题
I opened a bug report for this here因为根据一些评论,它应该有效。
Typescript 请注意,我更新了 github 存储库,删除了 @test
中的 glob 模式和斜杠。
最佳答案
不要调整 VS 代码导入模块说明符设置(根据一些答案)。并且不要删除 glob 模式。其实在里面多加一些:
"baseUrl": "./",
"paths": {
"@fs/*": ["src/*"],
"@test/*": ["test/*"]
},
请注意,glob 在键和值中。有时很难发现这一点。
如果目标是文件,则应从键和值中省略 glob。
关于javascript - typescript 路径无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55383929/