'Nrwl nx command to generate lib for nest module
I am new to nrwl nx cli and extensively searched through their documentation and could not find the command to generate the nestjs module as lib rather than the actual module within app.
The reason why I want to create the nestjs module as lib is becuase I have got several nestjs applications in my mono repo and as per nrwl nx guidelines if I have to share code, which is module in my case, it has to be a lib.
Can anyone please share the command to do the following thing:-
- Generate nestsjs module in libs
- Create nestjs service for that module in libs folder
Any help is much appreciated.
Solution 1:[1]
I got the command that does the job finally and sharing with other encase they require help
ng generate @nestjs/schematics:library mynestlib
Solution 2:[2]
Quote from Nx Workspace official documentation :
Creating a Lib Adding new libs to an Nx Workspace is done by using the Angular CLI generate command, just like adding a new app.
ng generate lib mylib ng generate library mylib # same thingThis will create a new lib, will place it in the libs directory, and will configure the
angular.jsonandnx.jsonfiles to support the new lib.Run
ng generate lib --helpto see the list of available options.
ng generate lib mylib --directory=myteamwill create a new application inlibs/myteam/mylib.
If --directory is not defined, it will ask you in which directory it should be generated, and what framework should be used (Angular or TS).
If it's not working, please, maybe you should check your Nx version, and also your angular.json.
@nrwl/schematics could not be the default collection used as this issue
mentioned.
angular.json
"cli": {
"defaultCollection": "@nrwl/schematics",
"packageManager": "yarn"
},
Solution 3:[3]
I've came across the same problematic lately.
While @Atul Chaudhary can solve the issue in a different way, I could solve my problem following this comment
So basically, you just have to add a new nest-cli.json file to your nx workspace root folder and specify these basic informations according to your project's structure.
nest-cli.json basic example
{
"collection": "@nestjs/schematics",
"sourceRoot": "apps/api/src"
}
Hope it can help some people :)
Solution 4:[4]
Nx now has direct support for NestJS via their @nrwl/nest plugin. They also have this tutorial that you may find useful.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Atul Chaudhary |
| Solution 2 | Joel |
| Solution 3 | A. Maitre |
| Solution 4 | wrslatz |
