tsconfig import alias paths ignored in nx Angular project when using Optimize Imports

Hi all!

I've got an Angular project that is managed with nx, with one app and several libraries.

In my tsconfig.base.json, I've got several paths defined, like @myApp/myLib/feature and @myApp/myLib/data-access

In Preferences | Editor | Code Style | TypeScript | Imports, I've set "Use path mappings from tsconfig.json" to "Only in files outside specified paths". (Directory imports and Merge imports are both enabled.) I'm using IntelliJ, but since it's a frontend project, I hope this is the right place to ask...

My expectation would be that when I need to import foo.ts from the feature library, it would use the alias as defined in tsconfig.base.json. However, it uses relative paths more often than not. That's driving me nuts.

What do I need to do to make IntelliJ use the aliases specified - and to replace relative paths with aliased once when using Optimize Imports?

(I don't want the replacement to happen if I'm importing a file from within the same library, ie. when they are under the same alias...)

1
2 comments

Hello Christian, Yes I am experiencing this issue too. The intelij cannot make imports correctly. I tried to install VSCode for comparison. There it is working like charm. So I think idea has a bug with import paths for TS. Thanks for post!

0

Optimize Imports is not currently designed to replace relative imports with absolute ones (https://youtrack.jetbrains.com/issue/WEB-52387)

As for auto-imports, they work as expected for me; sample app the issue can be repeated with would be helpful

0

Please sign in to leave a comment.