打字稿路径无法解析
Typescript paths not resolving
Here 的 Github MCVE 出现问题。 npm run compile
显示错误。
我正在尝试这样做:
import {Todo} from '@test';
但是没有解决。
src/index.ts:1:20 - error TS2307: Cannot find module '@test'.
我 paths
在 tsconfig.json
。
"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 打字稿问题
I opened a bug report for this here 因为根据一些评论它应该有效。
Typescript 请注意,我更新了 github 存储库,删除了 @test
中的 glob 模式和斜线。
删除 glob 模式:
"paths": {
"@test": "./test"
}
奇怪的是,您的解决方案应该有效,但是 the docs use no globs and 在使用 glob 时。
不要调整 VS 代码导入模块说明符设置(根据一些答案)。并且不要删除 glob 模式。其实在里面多加一些:
"baseUrl": "./",
"paths": {
"@fs/*": ["src/*"],
"@test/*": ["test/*"]
},
请注意,glob 在键和值中。有时很难发现这一点。
如果目标是文件,则应从键和值中省略 glob。
Here 的 Github MCVE 出现问题。 npm run compile
显示错误。
我正在尝试这样做:
import {Todo} from '@test';
但是没有解决。
src/index.ts:1:20 - error TS2307: Cannot find module '@test'.
我 paths
在 tsconfig.json
。
"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 打字稿问题
I opened a bug report for this here 因为根据一些评论它应该有效。
Typescript 请注意,我更新了 github 存储库,删除了 @test
中的 glob 模式和斜线。
删除 glob 模式:
"paths": {
"@test": "./test"
}
奇怪的是,您的解决方案应该有效,但是 the docs use no globs and
不要调整 VS 代码导入模块说明符设置(根据一些答案)。并且不要删除 glob 模式。其实在里面多加一些:
"baseUrl": "./",
"paths": {
"@fs/*": ["src/*"],
"@test/*": ["test/*"]
},
请注意,glob 在键和值中。有时很难发现这一点。
如果目标是文件,则应从键和值中省略 glob。