angularangular-materialnrwl-nx

Add Angular Material to Nx Workspace


I'm wanting to add angular-material to my nx-workspace.

The angular material docs (https://material.angular.io/guide/getting-started) say I should run ng add @angular/material.

I've tried that in the root of my nx workspace, as well as in an application folder I want to add it to, as well as in a lib project folder I want to add it to. In all cases I get the message The add command requires to be run in an Angular project, but a project definition could not be found.

The Angular Material docs used to include instructions on how to add dependencies manually, but I can't find that anymore. Does anyone know how to add it to projects in an Nx workspace these days?


Solution

  • First:

    Ensure you have Angular Material installed: npm i @angular/material

    Then:

    npx nx g @angular/material:ng-add --project=my-project-name is the command you need to run in your Nx Workspace.

    Do not forget to include the project name or you will see errors.

    Additionally, If you continue having errors try by answering no to the questions about Set up global Angular Material typography styles and Set up browser animations for Angular Material.

    Disclaimer: Another member already answered correctly in the comments but I think a simple answer like this one should be pinned.