-1

I'm using Angular 8. As per the business requirement, there is an isolated application that is separate from the main application but will be used in the main application.

For that I created a library using the command

ng generate library my-library

The my-library/package.json has following dependencies

{
  "name": "my-library",
  "version": "0.0.1",
  "peerDependencies": {
    "@angular/common": "^8.2.14",
    "@angular/core": "^8.2.14",
    "ngx-device-detector": "^1.4.5",
    "@fortawesome/fontawesome-svg-core": "^1.2.26",
    "@fortawesome/free-brands-svg-icons": "^5.12.0",
    "@fortawesome/free-regular-svg-icons": "^5.12.0",
    "@fortawesome/free-solid-svg-icons": "^5.12.0",
    "ngx-spinner": "^9.0.2"
  }
}

The library is inside the application in the project directory, thus the directory structure is

|- app
   |- package
      |- my-library
         |- src/
         |- package.json     # Library dependencies
   |- src                    # Main application
      |- app
      |- environments
   |- angular.json
   |- package.json           # Application dependencies

I installed the dependencies from /app directory

npm install

Then building the library using

ng build my-library

But this gives the error

...
Cannot find module 'ngx-device-detector'
...

How can I install the library dependencies?

Anuj TBE
  • 9,198
  • 27
  • 136
  • 285

2 Answers2

0

You probably didn't navigate to the library folder. Go to the terminal and enter the following command: cd app/package/my-library, this command navigates you to the library directory. It could be different depending on what your starting point is. Run the ng build command once you navigated to the library folder.

Moo
  • 48
  • 2
  • 9
0

You need to write the path of your library into main project package.json

"@my-library": "file:./package/my-library"

surendra kumar
  • 1,686
  • 11
  • 15