119

I am getting an error when trying to run npm run serve. At first I installed node.js then vue as well as vue/cli. But when I am trying to run server as -> npm run serve at that time I'm getting error like 'vue-cli-service' is not recognized as an internal or external command.

I used below codes for installation:

npm install -g vue
npm install -g @vue/cli

enter image description here

can someone guide me what to do to solve this issue ?

Dcoder14
  • 1,831
  • 3
  • 12
  • 22

23 Answers23

188

I think you are using cmd in windows.

Try deleting the node_modules folder and after that run npm i from the cmd.

Then try running npm run serve again and see if it works this time

s4k1b
  • 2,955
  • 1
  • 7
  • 14
  • 11
    @Sakib without deleting node_modules, it worked for me. Thanks – Dcoder14 Oct 27 '19 at 15:33
  • Done all step and when cmd using npm run serve then get error 'vue-cli-service' is not recognized as an internal or external command, operable program or batch file. – Krishna Soni Mar 27 '20 at 16:33
  • 2
    'vue-cli-service' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! smb-inseego@0.1.0 serve: `vue-cli-service serve` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the smb-inseego@0.1.0 serve script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\CC\AppData\Roaming\npm-cache\_logs\2020-03-27T16_32_39_297Z-debug.log – Krishna Soni Mar 27 '20 at 16:36
  • 2
    Try to install `vue-cli-service` run `npm install -g @vue/cli` then run `npm run serve` – s4k1b Mar 28 '20 at 17:11
  • Worked for me too, in my case when I incorrectly switched between two branches (git) and left some changes, that problem occurred. – Ali Afsahnoudeh Jul 08 '20 at 00:00
  • worked for me because i did npm needed to reinstall because it was installed on another platform. – SpiRail Nov 25 '20 at 19:46
  • this was perfect for my issue, switching between a non vue and back to a vue branch. – codeflower Dec 04 '20 at 11:09
59

Install vue/cli-service globally

npm install @vue/cli-service -g

This will install global npm package.

@vue/cli-service is usully installed as global, because you do not usually copy these types of packages to every project.

If the global npm package gets corrupted, it is not stored in node_modules folder, but rather in other depending on the os. Therefore removing node_modules does not help. Locations for global node_modules folders are

  • %USERPROFILE%\AppData\Roaming\npm\node_modules (Win10) or
  • /usr/local/lib/node_modules (Linux),

check this stack overflow post on how to locate global packages.

Scholtz
  • 2,878
  • 2
  • 23
  • 23
  • 4
    For me, personally, this is the only answer that helped – A Petrov Oct 16 '20 at 17:04
  • Same here.. together with https://stackoverflow.com/questions/53712893/vue-template-compiler-package-json-missing-module-with-every-new-project/53718006 – noontz Mar 24 '21 at 09:39
16

it will depend on the package manager you are using

  1. delete node_modules

  2. if you are using yarn run yarn or yarn install and then yarn serve

  3. if you are using npm run npm install and then npm run serve

4

In my case, the package @vue/cli-service is installed in my local node_modules environment, but not my global environment, so it cannot be used as a command. I type .\node_modules\.bin\vue-cli-service serve and it works.

3

As it is mentioned in terminal that node_modules is missing from your project, so you can't directly use npm run serve, first you have to do npm install then do npm run serve. It will work fine

  • This solved a similar problem I was having with building an ESP32 project, restful_server. npm install, then npm run build and the project would compile after the dist folder showed up. – BoredBsee Jul 13 '20 at 02:00
2

In my case I ran below commands in GitBash and it worked fine

  1. npm install
  2. npm run serve
Kiran Modini
  • 1,184
  • 8
  • 5
2
  1. If you are using cmd in windows.
  2. deleting the node_modules folder and after that run npm istall from the cmd.
  3. run npm run serve and see if it works this time
Ali Raza
  • 670
  • 5
  • 15
2

In my case, I have checked the folder of node_modules was missing. I am using Windows. So I run this in cmd.

  1. npm install
  2. npm run serve

Then I check it in localhost like usual.

ahartami
  • 21
  • 1
1

This issue mostly happens when either @vue/cli is not installed or in most cases,

@vue/cli is already installed and you are currently working on a project and when running

  • yarn serve or npm run serve.

Most at times, this issue is been caused by broken dependencies. to fix this issue, simple run

  • yarn install or npm install

depending on your package manager.

Romanric Akam
  • 663
  • 1
  • 5
  • 13
1

well after trying all the solutions above and it still haven't worked for you then you probably have a stupid space in the full directory of your Vue project like in my case. so remove that that space and it will work from then on.

1

Remember to set the NODE_ENV=development and run npm install again

1

Try changing the project path to one without spaces, it worked on windows 10

0

I had faced the same problem in windows. Then first I deleted the node_module. then I run npm install.

Hasibul-
  • 1,192
  • 1
  • 9
  • 18
0

For Windows you should modify package.json to:

  "scripts": {
    "serve": "vue-cli-service.cmd serve",
    "build": "vue-cli-service.cmd build",
    "lint": "vue-cli-service.cmd lint"
  }

,

0

I had the same issue using windows + WSL2 (Ubuntu 20.04). Looking at the logs generated after trying to run npm i I noticed that my WSL2 environment did not have python2 installed. So to solve I ran the following commands:

  1. sudo apt-get install python2
  2. rm -rf node_modules
  3. npm i
  4. npm run serve
Sales Lopes
  • 131
  • 1
  • 5
0

I faced the same in Windows. Had to run npm install again. Then it worked perfectly.

burke_
  • 21
  • 2
0

Wait, what's the difference between @vue/cli and @vue/cli-service? When you install both, they show different number of packages installed. The latter solved my issue actually but everyone keeps saying install @vue/cli.

0

try running npm i or npm install and then proceed to run npm i vue after previous installation done. works for me

0

you need use "npm install" at Command Line

Zest Zhang
  • 41
  • 4
0

Before running "npm install", try running this command first:

npm set strict-ssl false
ShieldOfSalvation
  • 1,297
  • 16
  • 32
0

Like you, I got the error below when I ran npm run serve from the CMD command line,

'vue-cli-service' is not recognized as an internal or external command, operable program or batch file.

I got past this familiar error by using the following command to add the npm folder to the PATH that CMD searches for executables:

path=%path%;C:\Users\<USERNAME>\AppData\Roaming\npm

where <USERNAME> is your Windows user profile directory name. Only then was I able to run the following commands successfully:

npm install 
npm run serve
ShieldOfSalvation
  • 1,297
  • 16
  • 32
0

What solved the issue for me was renaming the directory. I had used the symbol "&" on the folder name and it seems to break things, so changing it to "and" fixed the issue.

This will probably be an incredibly niche thing, but if I help even 1 person it's fine by me.

N1h1l1sT
  • 105
  • 1
  • 11
-1

I have a project, I can run it well on Linux, but i have the same issue on windows, I solve it this way (I hope in your case it works too):

  1. Delete the node_modules

  2. Install it again with npm i

Stefano Sansone
  • 2,377
  • 7
  • 20
  • 39
  • This has already been mentioned in some of the other answers. *When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers.* – Eric Aya Nov 02 '21 at 14:36