我有一个 Node.js Typescript 项目。我在 tsconfig.js
中声明了几条路径:
"paths": {
"@/*": [
"./*"
],
"@interfaces/*": [
"interfaces/*"
],
"@services/*": [
"services/*"
]
}
它们可以工作,我可以从这些文件夹中导入内容:
import { User, ErrorMessage } from '@interfaces/index';
import { UsersService } from '@services/index';
但是当我运行 tsc
时,输出文件中的路径不会被替换:
const index_1 = require("@services/index");
当然,这在 JavaScript 中不起作用……为什么 Typescript 不翻译路径?
此外,有趣的是,VSCode 强调了所有来自 @interfaces
的导入,声称该模块不存在,但不存在 @services
。