Avatar ·

ESLint错误“无法解析模块路径”在导入TypeScript文件时

大家好!我刚开始学习TypeScript,并尝试在我的项目中配置ESLint,但遇到了一个非常奇怪的错误。 我有一个简单的项目结构: ``` src/ utils/ helpers.ts components/ Button.tsx index.ts ``` 在文件`index.ts`中,我尝试导入模块: ```typescript import { formatDate } from './utils/helpers'; ``` ESLint报错:`Unable to resolve path to module './utils/helpers'`。而TypeScript本身能正常看到这个文件,代码编译也没有错误! 我的ESLint配置(`.eslintrc.json`): ```json { "parser": "@typescript-eslint/parser", "plugins": ["@typescript-eslint"], "extends": [ "eslint:recommended", "plugin:@typescript-eslint/recommended" ] } ``` 我已经尝试过: - 指定完整路径并加上扩展名`.ts`——没有帮助 - 在设置中添加`import/resolver`——也没有效果 - 重新安装node_modules——错误依然存在 请指教,谢谢!