nx: Create a new NestJS through a shcematic doesn't put it in the right folder
Prerequisites
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
- I am running the latest version (no, 8.3.0, since the latest one doesn’t work for me)
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
- I’m reporting the issue to the correct repository (not related to Angular, AngularCLI or any dependency)
Expected Behavior
I am using the Angular console to create a new NestJs controller. The outputted command is
ng generate @nestjs/schematics:controller mycontroller
I expect the controller to be placed inside my Nest application (apps/api)
Current Behavior
The output of the console is
CREATE src/mycontroller/mycontroller.controller.spec.ts (479 bytes)
CREATE src/mycontroller/mycontroller.controller.ts (97 bytes)
And indeed, the controller is put at the root of the projet, under a new folder src, not under apps/api.
Steps to Reproduce
- Create a Nx project
- Add a Nest projet
- Create a Nest controller as specified above
Context
- version of Nx used = 8.3.0
- version of Angular CLI used = 8.1.1
angular.jsonconfiguration = untouched- version of Angular DevKit used = 8.1.1
- 3rd-party libraries and their versions = non installed
Other
I have tried giving a path as the optional parameter, to no success. (still in src) I have tried giving a source root, to no success (still in src)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (9 by maintainers)
Dear @Maryannah ,
that is most likely, because
nrwl/nxdoes not ship with anest-cli.jsonfile in the root folder. This file, in turn, is used bynestjsto determine the source folder to put the generated files into…In order to fix your issue, simply create a
nest-cli.jsonfile in the root folder and add the following content:Please adapt the
sourceRootto your specific folder-structure… That should solve your issues…@vsavkin or @FrozenPandaz : Maybe we can add this
nest-cli.jsonfile to thenestschematics? What do you think about this?All the best
I was about to submit a similar issue until I came across this issue by @Maryannah - I would like to extend the discussion around this issue to accommodate or consider multiple Nest apps.
In my original case, I am using the Angular Console via VSCode and when I click on “Projects”, find my Nest application and click its “Generate” button, any
@nestjs/schematicsI go to generate (i.e. controller, module, etc.) results in something similar to the following:When I would expect something like this when generating off a Nest project via the “Projects” page:
Folks. I looked into it. It looks like generating a
nest-cli.jsonisn’t the best option because a workspace can contain many apps and libs.So I don’t think there is anything that needs to be done on the Nx side.
Your options are:
ng generate @nestjs/schematics:controller mycontroller --source-root=apps/api/srcexternalSchematic('@nestjs/schematics:controller')We are also working on improving Angular Console, so you can right click on a folder and invoke a schematic from it. We will keep this use case in mind, such that we either create
source-rootorprojectparameter based on the selected schematic.Well, while I’m not here to argue if the lack of the
nest-cli.jsonfile is a bug or not, my guess is that even if one was generated, I’d still have a problem or the inconvenience of generating Nestjs schematics for a specified Nestjs project.