0

When trying to install ng-bootstrap into a multi project mono repo using Nx I get the following error:

npx ng add @ng-bootstrap/ng-bootstrap --project=web-app

The add command requires to be run in an Angular project, but a project definition could not be found.

I am assuming this is because I am using project.json. It is an Angular project but without angular.json.

Markus
  • 2,214
  • 3
  • 19
  • 32
  • 2
    The problem is probably from the schematic that ng-bootstrap uses for an add. That schematic is specifically searching for angular.json (and is therefore not compatible with Nx). I think a manual install is easiest. – MikeOne Jun 13 '22 at 13:25
  • Good point from @MikeOne, the specific `getWorkspace` utility used by ng-bootstrap and many Schematics is quite an issue, it's changing form version to version and is not adapted to all kind of workspaces. But what is weird is the error message that @Markus is having. Anyway first question, did you keep angular.json format or switched to project.json ? Because in theory, Nx is compatible with angular.json. – Alain Boudard Jun 15 '22 at 08:15
  • Hey @AlainBoudard (we know each other :-)). I indeed assumed marcus is using project or workspace.json. I can remember having the same error about a year ago with firebase (before they updated their schematic to also look for workspace/project). There where discussions about nx temporarily generating an angular.json on an add to accommodate cases like this - but I don’t think they went through with it.. – MikeOne Jun 15 '22 at 10:49

1 Answers1

2

Ok, now as an answer I have this for you :

  • If you installed properly Nx AND an Angular project, you should have this message :
PS D:\tests\nx\demo> ng add @ng-bootstrap/ng-bootstrap --project myapp
Ng add is not natively supported by Nx
Instead, we recommend running `npm install @ng-bootstrap/ng-bootstrap && npx nx g @ng-bootstrap/ng-bootstrap:ng-add`
√ Run this command? (y/N) · true

But of course this will fail because the Nx schematics did not handle the --project parameter (there is a PR to be done I guess !) :

>  NX  Generating @ng-bootstrap/ng-bootstrap:ng-add

✔ Packages installed successfully.
SchematicsException [Error]: Unable to find project 'undefined' in the workspace

So, for your particular case, I'd say you did not choose the Angular option when scaffolding the Nx workspace, or you migrated to project.json ... or you did not run the ng add command from the proper directory.

Alain Boudard
  • 768
  • 6
  • 16