Intro
I was very confused with that rule when I recently ported the Ng code base to Nx 12.x. I hope this post helps others who begin migrating from Ng to Nx.
The code base above is a rather small single repo which is now used in production. When using Nx it's a good practice to follow the recommendations for monorepo to be able to use the monorepo benefits in the future as the code base is growing. (E.g. here I'm avoiding the overexposing of the code in the current repo).
I put the code base above into my-org/apps/my-small-repo
. By linting I was confused by the failure of the rule @nrwl/nx/enforce-module-boundaries
. So I tried different possibilities of mapping the src/app
of my-org/apps/my-small-repo
where either compiler or linter or both just failed.
I figured out the following solutions.
Solution 1
Just put
"compilerOptions": {
"baseUrl": "src"
},
into the root of apps/my-small-repo/tsconfig.json
and replace all of your imports inside of apps/my-small-repo
with imports beginning with app
.
Example for a DashboardComponent
:
import { DashboardComponent } from 'app/components/dashboard/dashboard.component';
Probably a better solution
This solution is tested on nx 13.x, but it probably works on previous versions of nx also.
Put
"app/*": ["apps/my-org/src/app/*"]
to the paths
in compilerOptions
of your tsconfig.base.json
in the repo root. Then put "allowCircularSelfDependency": true,
to the rule @nrwl/nx/enforce-module-boundaries
in the repo root.
We decided for "allowCircularSelfDependency": true,
to avoid working with ugly relative paths like like e.g. this one ../../../../../
in the app. And we also want to have library namespaces in tsconfig.base.json
only.
"allowCircularSelfDependency": true,
Thanks a lot! – Elusive