在编译时,我得到了无法修复的错误:/
index.ts:2:19 - error TS2307: Cannot find module '@shared'你知道为什么会这样吗?
项目结构:

tsconfig.json:
{
"compilerOptions": {
"outDir": "../../build/backend",
},
"extends": "../../configs/tsconfig.base.json",
"references": [
{
"path": "../shared"
}
],
"paths": {
"@shared": [
"../shared/index"
]
}
}backend/index.ts:
import 'module-alias/register'
import { x } from '@shared'
console.log(x)共享/index.ts:
export const x = 'this is shared index'发布于 2019-11-12 21:22:29
您可以使用以下命令来跟踪问题:
tsc --traceResolution我发现'@shared‘被用作文件夹名,所以它看起来像这样:
Resolving module name '@shared' relative to base url 'D:/apps/my-app/src' - 'D:/apps/my-app/src/@shared'.在我将别名更改为'shared‘并设置了baseUrl之后,一切都开始正常工作:
{
"compilerOptions": {
"moduleResolution": "node",
"baseUrl": "../",
"outDir": "../../build/backend"
},
"extends": "../../configs/tsconfig.base.json",
"references": [
{
"path": "../shared"
}
],
"paths": { "shared": ["shared/index"] }
}https://stackoverflow.com/questions/58809944
复制相似问题