0

I am an absolute beginner in Angular and I am finding some problem creating a component using the Angular CLI into an Angular project on which I am working on.

I manually created a subfolder (into my Angular project) in which I want create my new component, something like:

C:\Users\myusre\Source\Workspaces\MySolution\MyProject\WebProject\app\maildetail\maildetail-sidebar

I access to this folder into my shell and I execute this statment:

ng generate component main-detail-protocollo-sidebar

so I expect to obtain a new directory (into the previous directory) for my new component.

But I am obtaining this error message:

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

Why? What is wrong? What am I missing? How can I create a brand new component directly into the previous folder?

AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
  • I believe is a bug not totally solved: https://github.com/angular/angular-cli/issues/12198 and https://github.com/angular/angular-cli/issues/12215 -- Have you tried `ng g c testComponent`? I know is the same thing, but just for curiosity – Jacopo Sciampi Nov 12 '18 at 15:42
  • @JacopoSciampi mmm same problem – AndreaNobili Nov 12 '18 at 15:43
  • What about this? https://stackoverflow.com/questions/53096996/angular-cli-error-the-serve-command-requires-to-be-run-in-an-angular-project-b – Jacopo Sciampi Nov 12 '18 at 15:44

2 Answers2

2

You should be into the folder containing your angular.json

From there you can specify subpath in the component name, something likje this:

ng generate component subfolder/main-detail-protocollo-sidebar
firegloves
  • 5,581
  • 2
  • 29
  • 50
  • WOW this project doesn't contain the angular.json file. It is a .NET project that encapsulate Angular in some way :-/ – AndreaNobili Nov 12 '18 at 15:49
1

You must be inside your project folder either angular.json or angular-cli.json and try to run the generate command

ng generate component folder/main-detail-protocollo-sidebar --flat

Usually cli will generate a folder when you run the generate command to avoid that you can use --flat

Hope this helps - Happy coding :)

Rahul
  • 2,040
  • 2
  • 11
  • 29