1

I have a working angular workspace generated by nx. I am attempting to add angular material to the workspace with the following command:

ng add @angular/material

However I am getting the following error each time:

The add command requires to be run in an Angular project, but a project definition could not be found.
Exception: ng exited with 1

Relevant dependencies are as follows:

        "@angular-builders/custom-webpack": "11.0.0",
        "@angular-devkit/build-angular": "~0.1101.3",
        "@angular-eslint/eslint-plugin": "~1.1.0",
        "@angular-eslint/eslint-plugin-template": "~1.1.0",
        "@angular-eslint/template-parser": "~1.1.0",
        "@angular/cli": "^11.1.3",
        "@angular/compiler-cli": "^11.1.2",
        "@angular/language-service": "^11.1.2",
        "@jscutlery/semver": "^1.3.1",
        "@ngneat/tailwind": "^6.0.3",
        "@nrwl/cli": "11.2.10",
        "@nrwl/cypress": "11.2.10",
        "@nrwl/eslint-plugin-nx": "11.2.10",
        "@nrwl/jest": "11.2.10",
        "@nrwl/linter": "11.2.10",
        "@nrwl/storybook": "^11.2.10",
        "@nrwl/tao": "11.2.10",
        "@nrwl/workspace": "11.2.10",


    "dependencies": {
        "@activejs/core": "0.2.3",
        "@angular-architects/ddd": "^1.1.0",
        "@angular-architects/module-federation": "^1.2.3",
        "@angular/animations": "^11.1.2",
        "@angular/cdk": "11.1.2",
        "@angular/common": "^11.1.2",
        "@angular/compiler": "^11.1.2",
        "@angular/core": "^11.1.2",
        "@angular/elements": "11.1.2",
        "@angular/flex-layout": "11.0.0-beta.33",
        "@angular/forms": "^11.1.2",
        "@angular/material": "11.1.2",
        "@angular/platform-browser": "^11.1.2",
        "@angular/platform-browser-dynamic": "^11.1.2",
        "@angular/pwa": "0.1101.3",
        "@angular/router": "^11.1.2",
        "@angular/service-worker": "11.1.2",

I am using LinuxMint v20.x Thanks.

st_clair_clarke
  • 5,453
  • 13
  • 49
  • 75

2 Answers2

1

SOLUTION: npx nx g @angular/material:ng-add --project=my-project-name, as stated here: a solution for adding @angular/material to a Nx Workspace.


For making use of ng commands the nrwl team have decide to wrap them (decorate them) under his own cli. When facing a problem in your Nx Workspace related with libraries or the ng command, try these approaches and discover what works the better for your use case. E.g.:

  • nx generate @angular/material:ng-add --project=my-project-name
  • yarn add @angular/material
  • nx generate @nrwl/angular:component components/my-component --project=my-project-name (Important: use the project flag) to generate a component in the components folder of the project.
  • Use the raw ng CLI with: FORCE_NG_UPDATE=true nx your-ng-command-goes-here, where FORCE_NG_UPDATE is a variable set in the command line.
algife
  • 495
  • 4
  • 5
0

I reproduced the error when trying to run the command in a directory where is not an angular project present. Make sure you navigate to inside the project folder, for example: ~/projects/new-angular-app/, then run the command

Dharman
  • 30,962
  • 25
  • 85
  • 135
MarkusAfricanus
  • 113
  • 1
  • 16