Julia
Julia

Reputation: 51

How to use Angular library from npm package?

I have created a lib Angular by command:

ng generate library wrapper-cesium-panorama

Then I build it:

ng build cesium-panorama-lib

After I moved to /dict/cesium-panorama-lib folder and made:

npm publish

It cratead a npm package.

Then I have installed this package in existing Angular app:

npm i cesium-panorama-lib

It created package in /node_modules folder:

enter image description here

I try to use this library in Angular app:

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

It can not find path. Then I tried:

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

It works, but after build app I got this message:

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)

What do I do wrong and how to use it? I meantored that other packages has index.js in root directory

Upvotes: 1

Views: 468

Answers (1)

Zerotwelve
Zerotwelve

Reputation: 2361

you should export all your component and modules you want expose in public-api.ts

then when you have installed your library you should be able to import your modules/component like this: import { CesiumPanoramaLibModule } from "cesium-panorama-lib";

if you cannot import it like this, then you have a problem in your library

Upvotes: 1

Related Questions