1

I'm creating an Angular library and within tsconfig.lib.json I've added the following paths configuration:

 "compilerOptions": { "outDir": "../../out-tsc/lib", "target": "es2015", "declaration": true, "inlineSources": true, "types": [], "lib": [ "dom", "es2018" ], "paths": { "@fs/*": ["src/lib/*"] } } 

However attempting to import things like:

import { Test } from '@fs/Test' 

Does not work. Anyone know if Angular libraries support hte paths configuration option within tsconfig.lib.json?

Generally I use typescript-transform-paths to perform path transformation on the compiled result, and I was hoping Angular had baked something like this in for libraries?

2
  • It's a long shot but sometimes you have to reopen vscode and restart server for the new paths to be recognized. Try this if you haven't already. Commented Dec 5, 2019 at 19:17
  • In this case it's not recognizing it in the tooling. It will recognize it for normal Angular application projects, but it's not working in the library project. Commented Dec 5, 2019 at 19:47

1 Answer 1

2

Try using the following pattern in your tsconfig.json file :

"paths": { "@services/*": ["app/path/to/services/*"], "@components/*": ["app/path/to/some/deeply/nested/component/*"], "@environments/*": ["environments/*"] }, 

Then when importing:

import { yourServiceClass } from "@services/yourServiceClass"; 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! That works - I had to add it to the top level tsconfig.json file.
This is my Jest configuration in case someone is trying to do something similar: medium.com/@ole.ersoy/…
What am I missing, this looks exactly the same as the question. Is the only difference that it's at the top level and not in compilerOptions? If so, please put that in the answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.