0

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?

  • First you would want to check the module you get from NPM under node_module. See if they contain any folder / code or not before trying to use / import it – qkhanhpro Apr 03 '19 at 03:36
  • I have cheched the node_modules folder. it has nothing when i import the lib from the npm repo, so it is like the module was never exported – Cesar Leonardo Ochoa Contreras Apr 03 '19 at 03:39
  • Then you should revise the part where you publish the module to NPM Did you point to the correct directory ... etc , etc... Maybe try to publish a single random js file first to see if it works – qkhanhpro Apr 03 '19 at 03:42
  • It is the correct path (or directory). I have tried several times. The thing is the test with the npm pack command passing and the npm publish way failing. Its so weird thing. – Cesar Leonardo Ochoa Contreras Apr 03 '19 at 03:46

1 Answers1

0

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.