reactjs - 指向文件而不是目录时,Eslint 无法解析模块的路径
问题描述
我有一个带有 Typescript 的 React JS 项目,我使用 Eslint 进行 linting。我已经添加了路径别名tsconfig.json
,webpack.config.json
看起来像这样
// webpack.config.json
components: path.resolve(__dirname, './../src/components/')
...
和
// tsconfig.json
"components/*": ["components/*"],
...
所以,如果我有一个像import src/components/Button/index.tsx
as一样的文件components/Button
,Eslint 是安静的。
当我有一个像src/components/Loader.tsx
导入为components/Loader
. 短绒在这里抱怨Unable to resolve path to module 'components/Loader'
请注意:
- 项目编译成功。
- 我不想
"import/no-unresolved": 0
在我的eslintrc.json
我该如何解决这个问题?
解决方案
使用 components/Loader 与 components/Loader/index.tsx 相同,但在您的情况下,没有包含 index.tsx 文件的 Loader 文件夹要删除警告,请使用 loader 和 index.tsx 文件创建文件夹结构或明确定义您正在通过 components/Loader.tsx 访问文件
推荐阅读
- r - cut() 具有缺失值的变量
- python - 当 url 更改并添加 'offset=[# here]' 时,Web 抓取多个页面
- php - 不同站点上的 Wordpress 多站点调用插件功能
- excel - VBA,编译错误,预期的数组
- xamarin.forms - ios 模拟器未显示在我的 XamarinForms 项目中
- java - Java - 同步块的工作方式与方法不同
- javascript - 如果在javascript中启动后满足条件,则中断setTimeout倒计时
- php - 处理多个数据库之间的事务
- python - 百分位函数 Python
- c# - File Watcher 控制台应用程序在执行一次后关闭