import Locator from '@company/locator';
function func(locator: Locator) {
}
错误
TS2307: Cannot find module '@company/locator'
tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": { "@company/locator": ["node_modules/@company/locator"] }
"target": "esnext",
"lib": [
"esnext",
"es2017",
"es2016",
"es2015",
"dom",
"es6",
"es5"
],
"module": "esnext",
"sourceMap": false,
"strict": true,
"declaration": true,
"declarationDir": "types",
"types": [
"node",
"jest"
]
}
}
@company/locator
是我们用打字稿编写的节点模块。它包含一个名为Locator
的类。我正在尝试导入该课程。 Typescript编译器查找正确的路径(node_modules/@company/locator
)。但说没有找到locator.ts。 @company/locator
模块有一个types
文件夹,其中包含index.d.ts
。这就是定位器的导出位置。如何使编译器查看该@company/locator/types
文件夹。有人可以帮我解决这个问题吗?
tsc --traceResolution
给出
Module resolution kind is not specified, using 'Classic'.
'baseUrl' option is set to '/Users/lch/Documents/project', using this value to resolve non-relative module name '@company/locator'.
'paths' option is specified, looking for a pattern to match module name '@company/locator'.
Module name '@company/locator', matched pattern '@company/locator'.
Trying substitution 'node_modules/@company/locator/types', candidate module location: 'node_modules/@company/locator/types'.
File '/Users/lch/Documents/project/node_modules/@company/locator.ts' does not exist.
File '/Users/lch/Documents/project/node_modules/@company/locator.tsx' does not exist.
File '/Users/lch/Documents/project/node_modules/@company/locator.d.ts' does not exist.
Directory '/Users/lch/Documents/project/src/node_modules' does not exist, skipping all lookups in it.