question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Imports of apps are forbidden (nx-enforce-module-boundaries)

See original GitHub issue

Expected Behavior

I am importing a class from a Common workspace (library) and I should not have any linting errors.

Current Behavior

I am importing a class from a Common workspace (library), and the linting is throwing an imports of apps are forbidden (nx-enforce-module-boundaries).

Steps to Reproduce

I have a a Common workspace described as follows in angular.json:

    "feature-api-common": {
      "root": "libs/feature/api/common",
      "sourceRoot": "libs/feature/api/common/src",
      "projectType": "library",
      "schematics": {},
      "architect": {
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["libs/feature/api/common/tsconfig.lib.json", "libs/feature/api/common/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**", "!libs/feature/api/common/**"]
          }
        },
        "test": {
          "builder": "@nrwl/jest:jest",
          "options": {
            "jestConfig": "libs/feature/api/common/jest.config.js",
            "tsConfig": "libs/feature/api/common/tsconfig.spec.json",
            "passWithNoTests": true
          }
        }
      }
    }

with the following tags from nx.json:

    "feature-api-common": {
      "tags": ["shared"]
    }

This workspace doesn’t have a Nest module. I have a base entity with some date types, that I want to import. The entity is exported in an index.ts file, and then the path is as such in tsconfig.json:

"@team-management/api/common": ["libs/feature/api/common/src/index.ts"]

I have a different workspace, with a Nest module. In this module, I have an entity that I want to inherit from the common dated entity, as such:

import { DatedEntity } from '@team-management/api/common';
import { Column, Entity } from 'typeorm';

@Entity('exercise')
export class ExerciseEntity extends DatedEntity {
   ...
}

but it throws the imports of apps are forbidden (nx-enforce-module-boundaries) error.

This exercise workspace is described in the angular.json:

    "feature-api-exercises": {
      "root": "libs/feature/api/exercises",
      "sourceRoot": "libs/feature/api/exercises/src",
      "projectType": "library",
      "schematics": {},
      "architect": {
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "libs/feature/api/exercises/tsconfig.lib.json",
              "libs/feature/api/exercises/tsconfig.spec.json"
            ],
            "exclude": ["**/node_modules/**", "!libs/feature/api/exercises/**"]
          }
        },
        "test": {
          "builder": "@nrwl/jest:jest",
          "options": {
            "jestConfig": "libs/feature/api/exercises/jest.config.js",
            "tsConfig": "libs/feature/api/exercises/tsconfig.spec.json",
            "passWithNoTests": true
          }
        }
      }
    }

with the following tags in nx.json:

    "feature-api-exercises": {
      "tags": ["feature:api", "backend"]
    }

and these are my rules for nx-enforce-module-boundaries in tslint.json:

    "nx-enforce-module-boundaries": [
      true,
      {
        "enforceBuildableLibDependency": true,
        "allow": [],
        "depConstraints": [
          {
            "sourceTag": "app",
            "onlyDependOnLibsWithTags": ["shared", "feature:shared"]
          },
          {
            "sourceTag": "shared",
            "onlyDependOnLibsWithTags": ["shared"]
          },
          {
            "sourceTag": "feature:lazy",
            "onlyDependOnLibsWithTags": ["shared", "feature:shared", "feature:api"]
          },
          {
            "sourceTag": "feature:api",
            "onlyDependOnLibsWithTags": ["feature:api", "shared"]
          },
          {
            "sourceTag": "feature:shared",
            "onlyDependOnLibsWithTags": ["shared", "feature:api"]
          }
        ]
      }
    ]

As a comment, I can import this entity without linting error in a workspace with the tag app.

Context

"dependencies": {
    "@angular/animations": "9.1.0",
    "@angular/common": "9.1.0",
    "@angular/compiler": "9.1.0",
    "@angular/core": "9.1.0",
    "@angular/forms": "9.1.0",
    "@angular/platform-browser": "9.1.0",
    "@angular/platform-browser-dynamic": "9.1.0",
    "@angular/router": "9.1.0",
    "@auth0/angular-jwt": "^4.0.0",
    "@hapi/joi": "^17.1.1",
    "@nestjs/common": "^6.8.3",
    "@nestjs/config": "^0.4.0",
    "@nestjs/core": "^6.8.3",
    "@nestjs/passport": "^7.0.0",
    "@nestjs/platform-express": "^6.8.3",
    "@nestjs/swagger": "^4.5.1",
    "@nestjs/typeorm": "^7.0.0",
    "@nrwl/angular": "^9.1.4",
    "chalk": "^3.0.0",
    "class-transformer": "^0.2.3",
    "class-validator": "^0.11.1",
    "core-js": "^3.4.2",
    "jsonwebtoken": "^8.5.1",
    "moment": "^2.24.0",
    "ng-zorro-antd": "^8.5.2",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "~6.5.3",
    "sqlite3": "^4.1.1",
    "swagger-ui-express": "^4.1.4",
    "typeorm": "0.2.22",
    "zone.js": "^0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.901.0",
    "@angular/cli": "9.1.0",
    "@angular/compiler-cli": "9.1.0",
    "@angular/language-service": "9.1.0",
    "@nestjs/schematics": "^6.7.0",
    "@nestjs/testing": "^6.8.3",
    "@nrwl/cypress": "9.1.4",
    "@nrwl/jest": "9.1.4",
    "@nrwl/nest": "9.1.4",
    "@nrwl/node": "9.1.4",
    "@nrwl/workspace": "9.1.4",
    "@types/express": "^4.17.3",
    "@types/hapi__joi": "^16.0.12",
    "@types/jest": "24.0.9",
    "@types/node": "^12.12.12",
    "@types/passport-jwt": "^3.0.3",
    "circular-dependency-plugin": "^5.2.0",
    "clean-webpack-plugin": "^3.0.0",
    "codelyzer": "^5.2.0",
    "cypress": "^3.8.2",
    "dotenv": "^8.2.0",
    "eslint": "6.8.0",
    "jest": "24.1.0",
    "jest-preset-angular": "8.0.0",
    "prettier": "1.19.1",
    "prompt": "^1.0.0",
    "ts-jest": "24.0.0",
    "ts-node": "~8.5.2",
    "tslint": "6.0.0",
    "tslint-config-prettier": "^1.18.0",
    "typescript": "~3.8.3"
  }

Am I doing something wrong, like adding tags where I shouldn’t, or the Common workspace without a module shouldn’t be declared in angluar.json? Could it be a version error?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Splaktarcommented, Mar 15, 2021

AFAIK, @team-management/api/common is an invalid package name. You can only have @<scope>/<name> and not any nesting like @<scope>/api/common/legacy/core/state.

1reaction
omirobarcelocommented, Apr 7, 2020

It seems because I have an application named api it was causing some kind of conflict or misdirection. Changing the tsconfig.json path from:

"@team-management/api/common": ["libs/feature/api/common/src/index.ts"]

to

"@team-management-api/common": ["libs/feature/api/common/src/index.ts"]

solved it.

Thanks for the guidance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enforce Project Boundaries - Nx
Nx provides an enforce-module-boundaries eslint rule that enforces the public API of projects in the repo. Each project defines its public API in...
Read more >
eslint rule @nrwl/nx/enforce-module-boundaries fails [UPDATE]
Solution 1. "compilerOptions": { "baseUrl": "src" }, into the root of apps/my-small-repo/tsconfig. json and replace all of your imports inside ...
Read more >
Taming Code Organization with Module Boundaries in Nx
You can ban these imports using bannedExternalImports property in your dependency constraints configuration.
Read more >
nrwl-nx/community - Gitter
Hey guys, I enabled the rule "nx-enforce-module-boundaries". Now I am getting linting error because I do lazy loading of imports in one specific...
Read more >
ESLint: TypeError: Error while loading rule '@nrwl/nx/enforce ...
ESLint: TypeError: Error while loading rule '@nrwl/nx/enforce-module-boundaries': Cannot read property 'nodes' of null · "@angular/animations" · "11.2.0" · "@ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found