Angular 6 workspaces - Relative imports to an application from a library fails.
Using angular 6 new workspaces, you're able to place multiple projects alongside each other. When importing files from a project to another project, Intellij defaults to importing it by relative path, which will fail. Instead if should import it using the project-name.
My example: I have an application named 'my-app' and a library called 'my-lib. 'my-lib' contains a component called 'my-component' that I want to use in 'my-app'. When importing 'my-component' Intellij imports it like this...
import {MyComponent} from "../../../my-lib/src/lib/my-component";
This will not work, it needs to be
import {MyComponent} from "my-lib";
Is it possible for Intellij to default to this instead?
Please sign in to leave a comment.
You need modifying path mappings in tsconfig.json accordingly.
By default, ng generate library myLib creates the following mappings in main tsconfig.json:
But the dist folder is not there, and specified paths can't be resolved. You have to change the config as follows:
Thank you for your quick reply.
I always build my library (using ng build --prod --project my-lib) after making changes, so the dist/common is indeed there.
Trying your suggestion makes the imports look like this:
dist is auto-excluded due to https://youtrack.jetbrains.com/issue/WEB-30918 for better performance... And auto-import doesn't consider excluded folders:(
Does this mean there is no way forward right now? Are there any changes that could be made in future versions?
You can mark it as "not excluded": from the folder right-click menu, choose Mark directory as/Not Excluded
Thank you, it worked. Not sure if this is the best approach, but maybe it's the best available one for now!
The bug in this post is fixed. Why is this still an issue?
>The bug in this post is fixed
sorry, what bug?