Skip to content

@nx/enforce-module-boundaries recommends changes that break build of Angular library with secondary entry-points #30473

@dannymcgee

Description

@dannymcgee

Current Behavior

When an Angular library has multiple entry-points, imports that cross the boundaries of those entry-points must be specified by package name, e.g.:

// somewhere within '@scope/library/entry-point-a'
import { ... } from '@scope/library/entry-point-b';

Otherwise, attempting to build the library can fail with an extremely cryptic error message.

But the correct, package-specified imports are flagged by this ESLint rule:

Projects should use relative imports to import from other files within the same project.
Use "./path/to/file" instead of import from "@scope/library/entry-point-b"

Expected Behavior

@nx/enforce-module-boundaries should do one of:

  • Stop flagging package-specified intra-project imports completely, perhaps extracting this check to a separate lint rule
  • Stop flagging package-specified intra-project imports by default, but allow opting in to this check with a config option
  • Detect for the scenario above and avoid recommending these changes specifically when they're problematic (this seems like the most complex and error-prone option tbh, so probably not the one I'd recommend)

To be honest, I don't really understand why this check is part of this lint rule. The documentation says nothing at all about imports from within the same project — the purpose of this rule, as I understand it, is to enforce which projects are permitted to import symbols from which other projects. Including this secondary check just forces the user to disable the rule entirely if they don't want this behavior (or, in this more extreme case, if making the recommended change breaks something).

GitHub Repo

https://github.com/dannymcgee/electric/tree/cbeb736442d24a972a5a3be133e5eb3addb745f6

Steps to Reproduce

  1. Clone the linked repository
    • Be sure to checkout to the linked commit! I will likely have already pushed up a fix by the time you're investigating this
  2. Run npx nx build components
  3. Behold the inscrutable error message

Nx Report

Node           : 22.14.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 10.9.2

nx                     : 20.6.2
@nx/js                 : 20.6.2
@nx/jest               : 20.6.2
@nx/eslint             : 20.6.2
@nx/workspace          : 20.6.2
@nx/angular            : 20.6.2
@nx/devkit             : 20.6.2
@nx/eslint-plugin      : 20.6.2
@nx/module-federation  : 20.6.2
@nx/nest               : 20.6.2
@nx/node               : 20.6.2
@nx/rspack             : 20.6.2
@nx/web                : 20.6.2
@nx/webpack            : 20.6.2
typescript             : 5.7.3
---------------------------------------
Community plugins:
@ngneat/spectator : 19.4.1
angular-eslint    : 19.2.1
---------------------------------------
Cache Usage: 5.88 MB / 190.77 GB

Failure Logs

> nx run components:build:production

Building Angular Package

------------------------------------------------------------------------------
Building entry point '@electric/components'
------------------------------------------------------------------------------
- Compiling with Angular sources in Ivy partial compilation mode.

# NOTE: A whole bunch of Sass warnings omitted here because I don't think
# they're relevant. I've pasted one below for reference, but let me know if
# you want to see the rest of them.

WARNING: ▲ [WARNING] Deprecation [plugin angular-sass]

    src/lib/tabs/tab/tab.component.scss:18:1:
      18 │   padding: 12px;
         ╵   ^


  Sass's behavior for declarations that appear after nested
  rules will be changing to match the behavior specified by CSS in an upcoming
  version. To keep the existing behavior, move the declaration above the nested
  rule. To opt into the new behavior, wrap the declaration in `& {}`.
  
  More info: https://sass-lang.com/d/mixed-decls

✔ Compiling with Angular sources in Ivy partial compilation mode.
- Writing FESM bundles
✔ Writing FESM bundles
- Copying assets
✔ Copying assets
- Writing package manifest
✔ Writing package manifest
✔ Built @electric/components

------------------------------------------------------------------------------
Building entry point '@electric/components/accordion'
------------------------------------------------------------------------------
- Compiling with Angular sources in Ivy partial compilation mode.
✖ Compiling with Angular sources in Ivy partial compilation mode.
 NX   Cannot destructure property 'pos' of 'file.referencedFiles[index]' as it is undefined.
Pass --verbose to see the stacktrace.

——————————————————————————————————————————————————————————————————————————————

 NX   Ran target build for project components (4s)

   ×  1/1 failed
   √  0/1 succeeded [0 read from cache]

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Apologies the linked repo is not exactly a minimal reproduction. I ran into this issue after migrating from Nx and Angular v13 over the course of a few days. It's possible that the sequence of migrations left my components library in a state that would be uncommon to see nowadays and that the error is partly a result of that.

Metadata

Metadata

Assignees

Labels

priority: mediumMedium Priority (not high, not low priority)scope: angularIssues related to Angular support in Nxscope: linterIssues related to Eslint support in Nxtype: bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions