【发布时间】:2019-05-02 09:17:25
【问题描述】:
这个问题是How to use paths in tsconfig.json? 的后续问题,除了我想针对单个模块进行。
我有一个模块:
- 在
src/functions/foo.ts中实现 -
它的内容是:
export default interface Bar { } -
它是由另一个模块在其他地方使用非相对路径导入的:
import * as Foo from "foo"
编译器没有找到:
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 时使用(而不是在导入 * 时使用)?
(我在带有 Node.js 的 Windows 上使用 tsc 版本 3.1.6)。
【问题讨论】:
标签: typescript tsconfig