You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron+TypeScript项目导入TS文件时ESLint解析出错

Electron + TypeScript项目ESLint配置异常问题

项目结构

.
├── electron/
│   └── main/
│       ├── index.ts
│       └── test.ts
├── .eslintrc.json
├── tsconfig.json
└── tsconfig.node.json

相关文件内容

electron/main/index.ts

import { app, BrowserWindow, shell } from 'electron';

import { a, b } from './test' // 注意这一行

[...]

electron/main/test.ts

export const a = "a"

export const b = "b"  

问题现象

执行命令 npx eslint ./electron/main/test.ts 时出现解析错误,提示「TSConfig未包含该文件」。但出现以下几种情况时,test.ts可以正常被Lint:

  • 移除index.ts中的import { a, b } from './test'语句
  • 给导入路径添加.ts后缀,改为import { a, b } from './test.ts'
  • 改用require方式导入

尝试使用eslint-plugin-import和eslint-import-resolver-typescript插件后,问题仍未解决。以下是--debug模式下的相关日志片段:

eslintrc:ignore-pattern Check {
  filePath: 'C:\\project\\electron\\main\\test.ts',
  dot: false,
  relativePath: 'electron/main/test.ts',
  result: false
} +2ms
[...](省略重复错误信息)

内容的提问来源于stack exchange,提问作者sarotnem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 01:30:31