【问题标题】:Unable to use newly published Angular Library无法使用新发布的 Angular 库
【发布时间】:2020-11-10 05:31:57
【问题描述】:

我是发布 Angular 库的新手,这是我第一次尝试将名为 wps-ng https://www.npmjs.com/package/wps-ng 的库发布到 NPM。

我的公共 Api 文件看起来像 https://github.com/singkara/wps-js-ng/blob/library_test/projects/wps-ng/src/public-api.ts,我在其中导出了以下内容:

export * from './lib/wps-ng.service';
export * from './lib/wps-ng.component';
export * from './lib/wps-ng.module';

...

但是,当我在第 3 方 Angular 9 应用程序中执行 npm install wps-ng 时,它会失败并出现以下错误:

TS2307: Cannot find module 'wps-ng' or its corresponding type declarations.

虽然,我可以在与库本身相同的项目中使用同一个库(来自 dist 文件夹),但不能来自第三方应用程序(来自 node_modules 文件夹)。

对为什么会发生这种情况有什么想法吗?

提前致谢。

【问题讨论】:

  • 我认为您可能在 lib 的 package.json 文件中缺少 module 属性。它需要指向你的public_api.ts文件的编译js版本。
  • 感谢您的评论,我尝试在 package.json 中添加模块标签并将其指向 src/public_api.ts。但是,它没有用。

标签: angular typescript angular-cli angular-library


【解决方案1】:

我终于解决了这个问题, 我做错的是,我通过在库文件夹中运行命令npm publish 发布了库。

但是,执行此操作的正确方法是运行以下命令:

  1. ng 构建
  2. cd 目录
  3. cd your library name
  4. npm 包
  5. npm 发布

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多