我的項目結構是 的src/ 客戶端/ 模塊/ 服務器/ app.ts的baseUrl tsconfig.json不起作用
src/
client/
modules/
DB/
server/
app.ts
tsconfig.json
我導入使用非親屬導入模塊在app.ts文件
import * as DB from '@modules/DB';
,因爲我不想使用from "../modules/DB"
和我tsconfig.json是
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
"target": "ES6",
"noImplicitAny": true,
"sourceMap": true,
"preserveConstEnums": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"traceResolution": true,
"rootDir": "./src",
"outDir": "./dist",
"declaration": true,
"typeRoots": [
"/"
],
"baseUrl": "./src",
"paths": {
"@modules/*": [
"modules/*"
]
}
},
"exclude": [
"src/client/"
]
}
當我跟蹤的分辨率,得到這個
======== Module name '@modules/DB' was successfully resolved to '/Users/pengju/projects/pomelo-ts-starter/src/modules/DB/index.ts'. ========
似乎successfuly導入
但在編譯時, vscode仍然有錯誤
[ts] Cannot find module '@modules/DB'.
在import * as DB from '@modules/DB';
在app.ts
然後我檢查編譯app.js, 找到const DB = require("@modules/DB");
的的baseUrl和路徑選擇,無法改變 「@模塊/ DB」,以」 ../模塊/ DB「?那麼,他們做了什麼?