Reputation: 1071
I have created an Angular workspace that contains an application and a library, as explained here. The library contains a service that is exported in public-api.ts
.
The problem is that I cannot import the library services in the application. I get
Module not found: Error: Can't resolve 'lib-name/services/utils.service' in 'component-that-uses-the-service.ts'
Where lib-name
is the library created in the workspace.
The application does not throw any errors in Visual Studio Code, and the library module is imported in the component that uses it.
When I run the application with ng serve
I get the error message.
According to the Angular team:
When you build your own library, it has to find the mapping in your tsconfig paths.
The tsconfig paths seem OK, they were configured when I created the library with ng generate library
(the tsconfig file resides in the root of the workspace).
What am I missing?
Upvotes: 1
Views: 1363
Reputation: 359
If you've covered all your bases with exporting the right members and have your angular.json configured properly try updating your root tsconfig.json
my issue was that compilerOptions
didnt have the right path.
e.g.
{
compilerOptions: {
paths: {
"your-library": ["dist/your-library", "dist/your-library/your-library"]
}
}}
Upvotes: 0
Reputation: 14852
You do not need to import your service with the complete path.
you have to import your service like this
import { YourService } from 'lib-name'
Upvotes: 2