【发布时间】:2020-12-23 22:46:57
【问题描述】:
我看到一些关于this problem的问题,没有一个不起作用 我有一个 nodejs 项目和 Typescript。我不喜欢使用相对路径。在 tsconfig 中设置路径时出现以下错误:
找不到模块'@app/controllers/main'
// main.ts
export const fullName = "xxxx";
...
// app.ts
import { fullName } from '@app/controllers/main'
...
这是我项目的结构:
-node_modules
-src
----controllers
---------------main.ts
----app.ts
-package.json
-tsconfig.json
tsconfig:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"baseUrl": ".",
"paths": {
"@app/*": ["src/*"]
},
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
我的问题在哪里?
提前致谢。
【问题讨论】:
-
您是如何收到错误的?当您构建代码或 TSC 编译器时显示在 IDE 上?
-
当我想用这个命令运行项目时:
ts-node-dev src/index.ts -
有什么理由不使用纯
tsc代替吗?
标签: node.js typescript tsconfig tsconfig-paths