How to generate a component in Nativescript 8 and angular

Viewed 563

I just install all the requirements and setup my new Mac with Apple Silicon M1 Chip for Nativescript 8 development following their guide on https://nativescript.org. Now I created a new project running the command:

ns create

This asks for a name and what flavor you want, I choose Angular. Now I want to start creating new components but when trying to run the following command:

ng g c my-component

I get the following error:
The generate command requires to be run in an Angular project, but a project definition could not be found.

I already have the angular cli installed (version 12 latest) globally. What command should I run to create components or other stuff like services or modules; or do I need another package to do so.

2 Answers

You're missing angular.json in your project. And did you already install NativeScript Schematics? (npm i --save-dev @nativescript/schematics)

The file should have the following content:

{
    "version": 1,
    "cli": {
        "defaultCollection": "@nativescript/schematics"
    },
    "projects": {
        "my-project-name": {
            "root": "",
            "sourceRoot": "src",
            "projectType": "application",
            "prefix": "ns"
        }
    },
    "defaultProject": "my-project-name"
}

Replace my-project-name with the name of your project and run the generate command again.

NativeScript Documentation

Related