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

添加mysql2与sequelize后出现模块查找错误,如何不切换ES模块修复?

解决CommonJS项目中@typescript-eslint/utils/ts-eslint模块找不到的编译错误

可行解决方案(无需切换ES模块)

方案1:降级@typescript-eslint工具链到5.x版本

@typescript-eslint 6.x系列开始强制要求使用node16/nodenext/bundler模块解析策略,而5.x版本完全兼容旧版node解析模式,适合保留CommonJS的项目:

  1. 卸载当前的@typescript-eslint相关依赖:
yarn remove -D @typescript-eslint/eslint-plugin @typescript-eslint/parser
  1. 安装5.x稳定版本:
yarn add -D @typescript-eslint/eslint-plugin@5.62.0 @typescript-eslint/parser@5.62.0
  1. 重新编译项目即可。

方案2:通过tsconfig路径映射临时绕过解析问题

如果不想降级,可以在tsconfig.json的compilerOptions.paths中添加模块映射,强制指定类型文件路径:

{
  "compilerOptions": {
    // ... 其他原有配置
    "paths": {
      "@typescript-eslint/utils/ts-eslint": ["node_modules/@typescript-eslint/utils/dist/ts-eslint/index.d.ts"]
    }
  }
}

注意:此方法依赖@typescript-eslint/utils的内部目录结构,版本更新后可能失效,仅作为临时方案。

方案3:清理Yarn缓存并重新安装依赖

Yarn 4的虚拟包缓存可能导致依赖解析异常,执行以下命令重置依赖:

yarn cache clean
yarn install

问题根源与tsconfig优化建议

  • 错误原因:@typescript-eslint 6.x的内部模块使用了新的导入路径,旧版moduleResolution: node无法识别这些路径,而新版本工具链强制要求升级解析策略。
  • tsconfig优化:你的配置中paths: {"*": ["node_modules/*"]}是多余的,TypeScript默认会从node_modules查找模块,该配置可能干扰正常解析,建议移除。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 21:40:25