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

懵懂的女人 提交于 2019-12-06 00:53:05

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/50577261/error-this-command-can-only-be-run-inside-of-a-cli-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!