vscode intellisense-在排除的目录中找不到模块ts(2307)



在我的tsconfig.json中,我排除了文件夹

"src/__test__"

来自汇编。现在的问题是VS代码找不到模块。我用Jest运行测试没有问题,模块已经解决,但这个消息很烦人。我也不能使用自动完成。有没有一种方法可以为测试和源代码创建单独的typescript配置文件?到目前为止,我创建了tsconfig.test.json文件;延伸":"..//tsconfig.json";但它并没有像我预期的那样起作用。编译器只读库tsconfig.json.

找不到模块<gt;或其相应类型声明.ts(2307(

tsconfig.json

{
"compilerOptions": {
"module": "esnext",
"esModuleInterop": true,
"target": "es5",
"lib": ["es6", "dom"],
"sourceMap": false,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"baseUrl": ".",
"outDir": "dist",
"resolveJsonModule": true,
"paths": {
"components/*": ["src/components/*"],
"utils/*": ["src/utils/*"],
"api/*": ["src/api/*"],
"src/*": ["src/*"]
}
},
"exclude": ["src/__tests__"]
}

我找到了一个变通的解决方案。

通过在jest-config中添加这行代码,您将阻止jest运行dist文件夹中的*test.js文件:

{
...,
testPathIgnorePatterns: [
"<rootDir>/dist/"
]
}

然后,您可以在tsconfig中注释exclude行,这样错误就会消失。

最新更新