vite-tsconfig-paths: Unable to resolve transitive path
Maintainer note: See this comment for a solution.
Hey Alec,
I’ve just given this lib a spin and hit an issue in my mono repo where a mapped path tries to load another module in a mapped path and fails.
Here is the example:
/apps/frontend /libs/lib1 /libs/lib2
The libs have names/path mappings of @libs/lib1
and @libs/lib2
for instance.
Frontend loads lib1 fine, but lib1 tries to import lib2 and it can’t resolve.
I’ve tracked the issue down to isLocalDescendant
. My tsconfig is in /apps/frontend
, but because the importer is @libs/lib1
it thinks that lib2 is not a local descendant and it fails to resolve.
Solutions?
I basically need to be able to specify the root as the repo base (ie cwd()), and the tsconfigRoot as two separate options.
Possible non-breaking change, add a baseDir
option? Naming is hard, especially with the current value being called root
.
Ideas?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (9 by maintainers)
In v3.3.0, you should do the following:
root
option to point at the common ancestor shared by all projects whosetsconfig.json
files you want this plugin to useprojects
option undefinedI’ve tested with @jamos99’s demo, and it works as expected. 😃
I had the same issue. I created a new Nx workspace and created an app with the
@nxext/vite
package, then a few libraries using@nrwl/js
. Similar to the original post in this thread, the app depended on some libraries that then depended on other libraries within the workspace. When I tried to run the vite app by runningnx serve my-vite-app
it failed complaining that vite couldn’t resolve the transitive dependencies.In case anyone runs into this as well, to fix it I had to do all of the following (based on notes in this thread and elsewhere):
tsconfig.json
file to the root of the workspace (e.g./tsconfig.json
) extending the base tsconfig generated by Nx:vite.config.ts
file to the vite app (e.g./apps/my-vite-app/vite.config.ts
) containing the following (note that it provides aroot
property for thevite-tsconfig-paths
plugin pointing from the app’s directory to the root of the workspace:project.json
file (e.g/apps/my-vite-app/project.json
) to use the newly createdvite.config.ts
file instead of the one provided by@nxext/vite
:If I don’t do any part of the above I get the transitive dependencies error described in the original post and elsewhere, so I understand all are required to hook vite up to how Nx organises the workspace.
I ran into this issue with an nx monorepo, which for all intents and purposes uses Typescript paths for library resolution.
I created a demo at https://github.com/jamos99/vite-tsconfig-paths-demo using 3.2.1. It seems that paths resolve just fine if both libraries are used directly, but fail if one of the libs is only transitively imported (e.g. my-lib2 imports my-lib1).
@mwarnerdotme You’re facing another issue, specifically a bug in
tsconfig-paths
(https://github.com/dividab/tsconfig-paths/issues/new)Basically, the
include
inapps/my-app/tsconfig.app.json
is being overwritten by theinclude
inapps/my-app/tsconfig.json
PR welcome 😃