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

NX项目内使用TS别名路径报错,如何禁用强制相对导入?

解决NX项目中禁用同一项目内相对导入强制规则的方法

这个错误来自ESLint的@nrwl/nx/enforce-module-boundaries规则,要禁用同一项目内必须使用相对导入的限制,只需调整该规则的配置:

  • 打开项目根目录或目标子项目下的.eslintrc.json文件
  • 在rules节点下找到@nrwl/nx/enforce-module-boundaries规则,添加allowSameProjectImports选项并设为true

示例配置如下:

{
  "rules": {
    "@nrwl/nx/enforce-module-boundaries": [
      "error",
      {
        "allowSameProjectImports": true,
        // 保留你原有配置中的其他参数,比如allowedDependencies、depConstraints等
        "allowedDependencies": [],
        "depConstraints": []
      }
    ]
  }
}

配置完成后,同一项目内使用TS别名路径(比如import { fooHandler } from '@handlers/foo';)就不会再触发Projects should use relative imports to import from other files within the same project的错误提示。

内容的提问来源于stack exchange,提问作者S. C.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 08:10:30