我使用typescript并做出反应并设法通过遵循此link在VS Code中进行绝对导入,我遵循除步骤2之外的所有步骤,并且代码可以无问题地执行。但是在VS Code编译器中它会在图像中显示警告"Cannot find module"
,那么这是一种清除此警告的方法吗?
这是我的tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"jsx": "react",
"sourceMap": true,
"baseUrl": "./",
"paths": {
"custom": ["src/components/custom/"]
}
}
}
在你的tsconfig.json
中如果你在*
键中添加paths
并且值应该修复它,例如:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"jsx": "react",
"sourceMap": true,
"baseUrl": "./",
"paths": {
"custom/*": ["src/components/custom/*"]
}
}
}
这应该使导入指向文件夹custom
下的所有组件,并且它们可以作为custom/fileName
导入。它也应该自动完成。