nx: node-apps: unable to import custom paths from tsconfig.json
I have following setup for my node-app
when I run ng serve api i am getting Module not found error
tsconfig.json
"paths": {
"@env-api/*": [
"apps/api/src/environments/*"
],
}
config.service.ts
import { environment } from '@env-api/environment';
ERROR
ERROR in ./apps/api/src/config/config.service.ts
Module not found: Error: Can't resolve '@env-api/environment' in '/.../ngx-starter-kit/apps/api/src/config'
similar setup works for angular webapps
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 16 (8 by maintainers)
Commits related to this issue
- feat(builders): add support for `devtool` Fixes #902 — committed to samtsai/nx by deleted user 6 years ago
@konstantinschuette @jbjhjm this is kind of unreal to me that inside of Nx such a small thing like this is catastrophic for moving forward with global libs, right? This is crazy. I feel like the least the Nx team could do is let everyone know this is a limitation and provide a workaround.
I would guess that this is fixed by now. But I still experience this bug. Adding this to the root tsconfig.base.json works fine:
But not if you add it to a specific app.
Found my mistake: The paths in the main tsconfig get overwritten by the one in the app. I want to extend the paths. Is this possible?
@konstantinschuette no, this is still a limitation of tsconfig, unfortunately. As soon as you define a child paths list in a child file, it will discard the inherited paths. I think there was a larger discussion somewhere in the typescript repo issues. But can’t find it right now.
To make it short: Typescript devs say it is working as intended, there are no plans to add this feature so we likely have to live with this limitation.
I can guess that you are looking for a solution to use the same import path pointing to different file based on the selected project. To make that work, I ended up adding a custom/partial webpack config which resolves a “magic” configuration import. Also this magic path must not be imported into a ts file (as unknown to tsconfig). Use a js file to require the magic path and reexport using the js module. In tsconfig, add a path pointing to the js file. Good luck!
@jmcdo29 @xmlking fix is coming soon. I experienced the same issue. The reason for this is angular builder implements a different path resolution library than the nx builder which is used for non-angular projects & libraries. @FrozenPandaz has a fix in the makings (thx!) and it looks like all tests have passed and it’s going to be merged soon! 😃
@xmlking Did you ever figure out why this was happening? I’m trying to move an existing project into an nx workspace and I’ve come to the same issue. Angular web apps work, nestjs server apps do not.