Imports of apps are forbidden (nx-enforce-module-boundaries)
See original GitHub issueExpected 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:
- Created 3 years ago
- Comments:5 (1 by maintainers)
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
.It seems because I have an application named
api
it was causing some kind of conflict or misdirection. Changing thetsconfig.json
path from:to
solved it.
Thanks for the guidance.