Published angular library doesn't has imported modules on npmjs

405 views Asked by At

I want to publish a simple angular library in npmjs. So, the steps i followed was:

  1. Created the project:

    ng new my-project
    
  2. Created the library:

    ng g library my-lib
    
  3. Created a module to the library:

    ng g module module1 --project my-lib
    
  4. Write some code to the module:

  5. Added the library declaration to the public_api.ts file:

    export * from './lib/module1/module1.module';
    
  6. Build and publish the library:

    ng build my-lib
    cd dist/my-lib
    npm publish
    

When i test the library locally it works and the library has the exported module.

If i run

npm pack

and then import the library with

npm install --save path/to/my-lib.tgz 

in another project, it works and the library has the exported module.

BUT

when i install the library from the npm repo with

npm install --save my-lib 

the library download and install was ok but it is like the library was empty, so the desired module is missing and if i try to import the module in the project it fails and i get an error saying that the module doesn't exists.

How can i publish the library with the module or the modules that i want to keep available?

1

There are 1 answers

0
Cesar Leonardo Ochoa Contreras On

I solved the problem. In the 6th step, run:

ng build my-lib
cd dist/my-lib
npm pack
npm publish my-lib-0.0.1.tgz

now, it is published and contains everything i needed, and i can run npm install from the npm repo without any issues. The solution was simply running the npm pack command before and publish the tgz file instead of the dist file.