在关于如何使用 ng-packagr 创建Angular库的tutorial之后,我仍然坚持使用它 .

我有这个错误

./src/app/app.module.ts中的错误找不到模块:错误:无法解析'/ Users / username /中的'../../node_modules/my-ng-library/dist/public_api'开发/我的移动网络站点,前端/ src目录/应用”

文件夹结构是经典的,我使用了主 package.json 来包含

"ngPackage": {
    "$schema": "./node_modules/ng-packagr/ng-package.schema.json",
    "lib": {
      "entryFile": "public_api.ts"
    },
    "dest": "dist"
  },

运行 ng-packagr -p package.json 一切顺利得到一个/ dist文件夹,如
enter image description here

public_api.d.ts

export { BannerModule } from './src/app/components/banner/banner.module';
export { BannerComponent } from './src/app/components/banner/banner.component';

源模块是:

import { BannerComponent } from './banner.component';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

@NgModule({
  imports: [
    CommonModule
  ],
  exports: [
    BannerComponent
  ],
  declarations: [BannerComponent],
  providers: []
})
export class BannerModule { }

另外在我想使用这个库中的组件的项目中,我需要像这样导入(否则我得到另一个关于找不到模块的错误)

import { BannerModule } from '../../node_modules/my-ng-library/dist/my-ng-library';