How to specify published package.json with library publishing in angular 6?


Creating node modules with Angular6 should be quiet easy. The Documentation tells you these steps:

  1. ng generate library YOUR-LIBRARY
  2. ng build YOUR-LIBRARY --prod
  3. cd dist/YOUR-LIBRARY && npm publish

This will add for instance a new project inside your angular.json, create a new directory inside /projects and compile/transpile your package into /dist/YOUR-LIBRARY. Thats super nice, BUT I cannot find the configuration approach to specify the exported package.json inside the dist directory.

I’ve tried to modify the package.json inside /projects but it does not have any effect on the distributed package.json.

It allways looks like:

  "name": "YOUR-LIBRARY",
  "version": "0.0.1",
  "peerDependencies": {
    "@angular/common": "^6.0.0-rc.0 || ^6.0.0",
    "@angular/core": "^6.0.0-rc.0 || ^6.0.0"
  "main": "bundles/nls-guilloche.umd.js",
  "module": "fesm5/nls-guilloche.js",
  "es2015": "fesm2015/nls-guilloche.js",
  "esm5": "esm5/nls-guilloche.js",
  "esm2015": "esm2015/nls-guilloche.js",
  "fesm5": "fesm5/nls-guilloche.js",
  "fesm2015": "fesm2015/nls-guilloche.js",
  "typings": "nls-guilloche.d.ts",
  "metadata": "nls-guilloche.metadata.json",
  "sideEffects": false,
  "dependencies": {
    "tslib": "^1.9.0"

I cannot even change the version tag or add any information. Sure, manually it would work, but this cannot be the solution, can it?


As of Angular 12.x each library has a package.json that gets generated and that file is the one that gets copied over into the output directory (dist/ in your case).

It looks something like this when it’s generated:

// projects/my-lib/package.json
  "name": "my-lib",
  "version": "0.0.1",
  "peerDependencies": {
    "@angular/common": "^12.0.0",
    "@angular/core": "^12.0.0"
  "dependencies": {
    "tslib": "^2.1.0"

Answered By – KhalilRavanna

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.