K.Shikha
K.Shikha

Reputation: 107

Include dependencies in Angular CLI libararies

I'm having issues with including Angular material dependency in the custom library. The primary application that includes a reference to the custom library throws an error "Cannot find @angular/material/core" and "@angular/material/tabs" while building the application. But these dependencies are present in the node_modules of the library.

I read online that adding the following to the library's package.json

"dependencies": {
    "@angular/animations": "^8.2.14",
    "@angular/cdk": "^8.2.3",
    "@angular/material": "^8.2.3"
  }

should solve this issue, but it didn't seem to work.

After listing the dependencies, I did npm install to install the above listed packages. When I do an ng serve in the primary application, it does not include @angular/material and @angular/cdk in the node_modules of the primary application. enter image description here

I would like my library to be self-contained and include angular/material when it is installed. Am I missing something?

Upvotes: 0

Views: 774

Answers (1)

Celsiuss
Celsiuss

Reputation: 905

You cannot use those libraries in your primary application without explicitly depending on them. Even though they are getting installed via your custom dependency, node will not recognize those in your primary application. You need to also add them to your package.json in your primary application.

Upvotes: 0

Related Questions