这个问题是后续问题如何使用 tsconfig.json 中的路径? https://stackoverflow.com/q/43281741/49942但我想为单个模块执行此操作。
我有一个模块:
编译器没有找到它:
error TS2307: Cannot find module 'foo'
这个 tsconfig 不能解决这个问题......
{
"compilerOptions": {
"noEmit": true,
"strict": true,
"module": "commonjs",
"target": "es2017",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "build",
"baseUrl": ".",
"paths": {
"foo": ["src/functions/*"],
"*": [
"node_modules/*"
]
}
},
"include": [
"./src/**/*", "./typings/**/*", "./test/**/*", "./test-integration/**/*"
]
}
...但这确实:
"paths": {
"*": [
"node_modules/*",
"src/functions/*"
]
}
为什么第一版没有paths
工作 --- 我做错了什么,我能做什么来确保"src/functions/*"
仅在导入时使用foo
(而不是在导入时*
)?
(我在 Windows 上使用 tsc 版本 3.1.6 和 Node.js)。