Skip to content

ESLint 解决 TypeScript 路径别名错误:Cannot find module

Published: at 08:20 AMSuggest Changes

问题

Webpack 中配置了路径的别名 @ ,但是在使用的时候,Eslint 报错了:

import { useAppSelector, useAppDispatch } from '@/redux/hooks'; // error TS2307: Cannot find module '@/redux/hooks'

解决问题

在 tsconfig.json 中配置 paths

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  }
}

Previous Post
Mac 双网卡配置方案
Next Post
Webpack Alias 别名配置