0

Getting error if I use serve for libraries:

An unhandled exception occurred: Project library_name does not support the 'serve' target.
See "/tmp/ng-oggHbf/angular-errors.log" for further details.
nickgryg
  • 25,567
  • 5
  • 77
  • 79
pkvd
  • 91
  • 1
  • 9
  • 1
    What would ng serve do? It's a library, not an application. There's nothing that can be served. What are you trying to achieve? – JB Nizet Oct 12 '19 at 07:16
  • For local development of libraries i want to use ng serve. Angular documentation says https://angular.io/cli/serve we can use ng serve for libraries. But when i use this it gives error saying An unhandled exception occurred: Project library_name does not support the 'serve' target. See "/tmp/ng-oggHbf/angular-errors.log" for further details. – pkvd Oct 12 '19 at 08:46
  • The documentation is misleading. It makes no sense to *serve* a library. Think about it: imagine it worked: **what** could it posibly do? – JB Nizet Oct 12 '19 at 09:13
  • `CLI` would be not installed. Running `npm install @angular/cli` would fix this error. – Ali Soltani Oct 12 '19 at 13:07
  • CLI is installed. I can able to run ng build --project project_name --watch true with out any errors. – pkvd Oct 14 '19 at 04:24
  • Does this answer your question? [Angular serve library](https://stackoverflow.com/questions/54146811/angular-serve-library) – Anshita Singh Apr 20 '20 at 19:28

1 Answers1

1

Yes, error is true. We can't serve angular library and even there is no point to serve the library since it's not application. Still if you want to test your library there could be 2 ways:

  1. Build and Push your library to some registry and add as a dependency in your application and test it.
  2. Build your library and once dist folder is created for your library then point that dist folder from your application and add dependency of library in your application. something like this:

In package.json:

"dependencies": {
    "library-name" : "file:<local dist folder location>"
  }

I use to prefer second approach. You can also get detail explanation here: Angular serve library

Anshita Singh
  • 1,583
  • 1
  • 17
  • 40