Angular 14: Error: A collection and schematic is required during execution
Asked Answered
B

4

14

I am trying to learn angular. I installed the lastest version and created an app called test using ng new test command.

Then I opened the app in visual studio code. In the terminal I entered the following command to create a new component: ng g form1

I get the following error:

Error: A collection and schematic is required during execution.

Please see the screenshot. Please help. Thanks.

screenshot of error

Berar answered 20/10, 2022 at 17:5 Comment(0)
H
20

https://angular.io/cli/generate

A schematic is the type of object you want to create, such as a service, pipe, directive, or component.

In this instance, you're providing the name of what you want to generate ('form1') but not what kind of object.

You could run ng g c form1 to generate a form1.component, or ng g s form1 to generate a form1.service.

Ha answered 20/10, 2022 at 17:40 Comment(0)
G
2

The command is wrong. Please try to use the command below.

ng g c "MODULE-NAME"

Here g is for generate and c stand for component.

Gomer answered 14/6, 2023 at 13:54 Comment(0)
P
1

Sometimes you are using

ng g form1

watch this issue "Error: A collection and schematic is required during execution."

You can not use only

ng g form1

Specify the module using the --module parameter. For example, if the main module is app.module.ts, run this:

ng g c new-component --module app
Perdu answered 3/2, 2023 at 13:57 Comment(1)
brilliant! this was my issueThew
G
1

The correct format is ng <action> <schema> <path/filename>

In your case you are probably trying to generate a component which could be something like:

ng generate component form1 or

ng g c form1 (shorthand)

Goosander answered 11/10, 2023 at 2:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.