Use native workspace package linking instead of tsconfig paths. #20005
ajwootto
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Typescript warns against using "paths" in the way Nx does to link Monorepo packages together
https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths-should-not-point-to-monorepo-packages-or-node_modules-packages
I know Nx relies heavily on the "paths" to power its executors and enable "hot reloading" etc., but I wonder if any thought has been given to migrating off that system and using something more native. All major package managers support workspace linking, and that seems like a much more properly supported way of connecting packages locally together.
The current default approach of building libs into the
dist/
directory and then internally rewriting the tsconfig paths to point to those dist/ outputs during builds of packages that depend on them also has drawbacks. It relies on "relative packages" which are not treated the same way in Node as a "node_modules/" package, as demonstrated by this issue:#18324
Typescript docs also call out the use of "relative modules" in the linked documentation page:
So with my current understanding, it seems like Nx is relying on a "legacy" feature in order to build things together correctly.
It may also be worth considering whether the
"imports"
field can achieve some of the behaviour nx is trying to do itself today, like referencing source files during development and automatically switching to dist/ output files during build:https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-imports-and-self-name-imports
It feels like a lot of the tricks / plugins / patches Nx has to apply to various tools might be significantly simplified / made not necessary by this.
Beta Was this translation helpful? Give feedback.
All reactions