Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error - This command can only be run inside of a CLI project

Tags:

angular

ionic3

I am working on an ionic 3 project with the name portal. I need to create a service called user but i keep getting the above error. These are the steps i followed:

cd portal 
npm install -g angular-cli@latest
npm install
ng g service user

Then i get the error This command can only be run inside of a CLI project. I noticed that angular-cli is not getting added to my dependency list in package.json nor do i have the cli directory under @angular in the node modules directory. I tried the install angular-cli twice but the error persists. Have been stuck with it for a long time any help is really appreciated.

like image 885
rini saha Avatar asked May 29 '18 06:05

rini saha


2 Answers

Ok let me, instead of commenting, write an answer.

The error occurs because you're using the Angular CLI in a project which isn't generated by the Angular CLI, thus missing configuration files.

Since you're stating that you have an ionic 3 application, you don't need the angular CLI.

Step 1: create project (you probably have done this one)

ionic start portal blank  

Step 2: go into your project

cd portal

Step 3: (npm install is already done, just generate a service)

ionic generate provider user
like image 117
Ivar Reukers Avatar answered Nov 19 '22 00:11

Ivar Reukers


Your steps must be in this order:

1) Install angular globally

npm install -g angular-cli@latest

2) Create the app at a directory location

ng new portal 

3) Go into that folder

cd .\portal\

4) Install node modules

npm install

5) Generate service

ng g service user

If your commands are not in this order, you will have an error.

like image 35
Prachi Avatar answered Nov 18 '22 23:11

Prachi