[英]Eslint's Unable to resolve path to module when pointing to file and not a directory
我有一个带有 Typescript 的 React JS 项目,我使用 Eslint 进行 linting。 我已将路径别名添加到tsconfig.json
和webpack.config.json
看起来像这样
// webpack.config.json
components: path.resolve(__dirname, './../src/components/')
...
和
// tsconfig.json
"components/*": ["components/*"],
...
所以,如果我有一个像src/components/Button/index.tsx
导入为components/Button
的文件,Eslint 是安静的。
当我将像src/components/Loader.tsx
这样的文件导入为components/Loader
时,问题就来了。 在这里,linter 抱怨Unable to resolve path to module 'components/Loader'
请注意:
eslintrc.json
上使用"import/no-unresolved": 0
来抑制此警告我该如何解决这个问题?
使用 components/Loader 与 components/Loader/index.tsx 相同,但在您的情况下,没有包含 index.tsx 文件的此类 Loader 文件夹要删除警告,请使用 loader 和 index.tsx 文件创建文件夹结构或明确定义您正在通过 components/Loader.tsx 访问文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.