You need to enable JavaScript to run this app. TypeScript中如何禁用unicorn/prefer-module并解决规则未找到报错
优惠活动
大模型
产品
解决方案
定价
更多

TypeScript中如何禁用unicorn/prefer-module并解决规则未找到报错

报错原因

你安装的eslint-plugin-unicorn版本为v32.0.1,unicorn/prefer-module规则是该插件v34.0.0版本才新增的能力,当前版本不存在对应规则,所以会抛出「Definition for rule 'unicorn/prefer-module' was not found」的报错。同时你使用的xo@0.40.3内置依赖的unicorn插件版本也低于v34,默认不会加载该规则。

解决方法

如果你确实需要使用并禁用该规则

  1. 先升级eslint-plugin-unicorn到v34.0.0及以上版本,执行命令:
npm install eslint-plugin-unicorn@latest --save-dev
  1. 全局禁用规则:在package.json的xo.rules配置项中添加规则即可:
{
  "xo": {
    "rules": {
      "unicorn/prefer-module": 0
    }
  }
}
  1. 单文件临时禁用:升级完成后,再在文件顶部添加/* eslint-disable unicorn/prefer-module */注释即可正常生效。

如果你只是要支持CommonJS的require语法

你当前配置已经关闭了@typescript-eslint/no-require-imports规则,已经可以正常使用require写法,无需额外处理不存在的unicorn/prefer-module规则。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.15 04:45:02