【发布时间】:2021-07-02 20:37:47
【问题描述】:
我有一个带有 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来抑制这个警告
我该如何解决这个问题?
【问题讨论】: