node.jsmonoreponrwl-nxnrwlnxjs

NX Error for Relative Imports within the Same Project


I'm getting an error when using TS aliased paths within the same project: Projects should use relative imports to import from other files within the same project

I don't want this behavior. Any idea how to disable?

I tried playing with the @nrwl/nx/enforce-module-boundaries option, but it has almost no documentation around its options

// NX doesn't like this line which uses a path to a file within the
// same NX project. It wants me to use relative pathing, which I
// don't want to use
import { fooHandler } from '@handlers/foo';

Solution

  • Had to look through the npm package, but found it by searching for the error text. You can disable it like this from inside of your .eslintrc.json settings:

    {
      "overrides": [
        {
          "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
          "rules": {
            "@nrwl/nx/enforce-module-boundaries": [
              "error",
              // This is the part you need to add
              { "allowCircularSelfDependency": true }
            ]
          }
        }
      ]
    }