【发布时间】:2019-11-01 04:37:14
【问题描述】:
我正在尝试为我的模拟服务器设置别名。每当我尝试编译 ts 文件时,它都会返回错误,即即使在 tsconfig,json->paths 中定义了正确的模块,它也找不到合适的模块。
文件夹结构:
├── server
│ └── src
│ └──/json
├── src
│ └──/modules
├── tsconfig.json
这是我的tsconfig.json
{
"compilerOptions": {
"baseUrl": "./src",
"experimentalDecorators": true,
"jsx": "react",
"lib": [
"dom",
"es2015",
"es2015.promise"
],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"paths": {
"@project/app/modules/*": [
"modules/*"
],
"@project/server/data/*": [
"../server/src/json/*"
]
},
"sourceMap": true,
"target": "es5"
},
"exclude": [
"node_modules",
"tools"
]
}
错误:
Error: Cannot find module '@project/server/data/accounts/accountsList'
【问题讨论】:
-
它是否适用于@project/app/modules/*?
-
不行,没有一个别名可以解析
-
我的配置,包含指向 ['src'] 的标志。试试看。
-
你碰巧在 webpack 中使用它吗?
-
谢谢!最终使用
tsconfig-paths包。
标签: typescript alias tsc tsconfig ts-node