question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create a new NestJS through a shcematic doesn't put it in the right folder

See original GitHub issue

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

  1. Create a Nx project
  2. Add a Nest projet
  3. Create a Nest controller as specified above

Context

  • version of Nx used = 8.3.0
  • version of Angular CLI used = 8.1.1
  • angular.json configuration = 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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
johannesschobelcommented, Jul 31, 2019

Dear @Maryannah ,

that is most likely, because nrwl/nx does not ship with a nest-cli.json file in the root folder. This file, in turn, is used by nestjs to determine the source folder to put the generated files into…

In order to fix your issue, simply create a nest-cli.json file in the root folder and add the following content:

{
  "language": "ts",
  "collection": "@nestjs/schematics",
  "sourceRoot": "apps/api/src"
}

Please adapt the sourceRoot to your specific folder-structure… That should solve your issues…

@vsavkin or @FrozenPandaz : Maybe we can add this nest-cli.json file to the nest schematics? What do you think about this?

All the best

2reactions
METACEOcommented, Aug 11, 2019

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/schematics I go to generate (i.e. controller, module, etc.) results in something similar to the following:

ng generate @nestjs/schematics:module storage --dry-run --no-interactive
CREATE src/storage/storage.module.ts (84 bytes)
NOTE: The "dryRun" flag means no changes were made.
Process completed

When I would expect something like this when generating off a Nest project via the “Projects” page:

ng generate @nestjs/schematics:module storage --path=app --sourceRoot=apps/api/src --dry-run --no-interactive
CREATE apps/api/src/app/storage/storage.module.ts (84 bytes)
UPDATE apps/api/src/app/app.module.ts (426 bytes)
NOTE: The "dryRun" flag means no changes were made.
Process completed
Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting a custom build directory - next.config.js
Set a custom build directory to use instead of the default .next directory.
Read more >
Next.js 12 Output File Tracing Fails to Build #9017 - GitHub
Current Behavior create a new nx workspace w/ a next.js app turn on next.js output file tracing run nx build --prod build fails...
Read more >
How To Develop and Build Next.js App with NodeJS Backend
If you look at the above project structure, all the Next. js app resides under the my-app folder and nodejs API resides under...
Read more >
React | WebStorm Documentation - JetBrains
The recommended way to start building a new React single page ... In the right-hand pane, specify the application folder and click Create....
Read more >
Create a Markdown Blog Using Next.js - Joy of Code
Static doesn't mean not dynamic because we're still using React on ... Let's add some example posts by creating a posts folder at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found