【发布时间】: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