'Module not found' 在同一工作区中导入图书馆服务时

'Module not found' when importing a library service in the same workspace

我创建了一个 Angular 工作区,其中包含一个应用程序和一个库,如 here 所述。该库包含在 public-api.ts.

中导出的服务

问题是我无法在应用程序中导入图书馆服务。我得到

Module not found: Error: Can't resolve 'lib-name/services/utils.service' in 'component-that-uses-the-service.ts'

其中 lib-name 是在工作区中创建的库。

应用程序不会在 Visual Studio 代码中抛出任何错误,并且在使用它的组件中导入了库模块。

当我 运行 带有 ng serve 的应用程序时,我收到错误消息。

根据 Angular 团队:

When you build your own library, it has to find the mapping in your tsconfig paths.

tsconfig 路径似乎没问题,它们是在我使用 ng generate library 创建库时配置的(tsconfig 文件位于工作区的根目录中)。

我错过了什么?

您不需要使用完整路径导入您的服务。

你必须像这样导入你的服务

import { YourService } from 'lib-name'