繁体   English   中英

如何使用 npm 包中的 Angular 库?

[英]How to use Angular library from npm package?

我通过命令创建了一个 lib Angular:

ng generate library wrapper-cesium-panorama

然后我构建它:

ng build cesium-panorama-lib

在我移动到/dict/cesium-panorama-lib文件夹并制作后:

npm publish

它创建了一个 npm 包。

然后我在现有的 Angular 应用程序中安装了这个包:

npm i cesium-panorama-lib

它在/node_modules文件夹中创建了包:

在此处输入图像描述

我尝试在 Angular 应用程序中使用这个库:

import { CesiumPanoramaLibModule } from "cesium-panorama-libi";

它找不到路径。 然后我尝试了:

import { CesiumPanoramaLibModule } from "cesium-panorama-lib/src/public-api";
imports: [CesiumPanoramaLibModule]

它可以工作,但是在构建应用程序之后,我收到了以下消息:

ERROR in ./node_modules/cesium-panorama-lib/src/public-api.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: C:\Users\poDesktop\AngularPrototype\node_modules\cesium-panorama-lib\src\public-api.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format
    at AngularCompilerPlugin.getCompiledFile (C:\Users\ponom\Desktop\AngularPrototype\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:913:23)

我做错了什么以及如何使用它? 我的意思是其他包在根目录中有index.js

您应该导出您想要在public-api.ts中公开的所有组件和模块

那么当你安装了你的库时,你应该能够像这样导入你的模块/组件: import { CesiumPanoramaLibModule } from "cesium-panorama-lib";

如果你不能像这样导入它,那么你的图书馆有问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM