npm command 'serve ' not found, although it is installed
Asked Answered
B

7

39

I have installed serve with npm as "npm install serve -g" and also with yarn "yarn global add serve", but when I try to run "serve -s build" it says that "Command 'serve' not found.

Bess answered 5/4, 2019 at 7:3 Comment(3)
it should work, can you try to uninstall and reinstall it using npm?Nostology
Still doesn't work. But I managed to install it locally (only to my project folder) with npxBess
okay you can may be change global installation for node_module ref: #5927172 may be this can help you outNostology
S
43

You should not install the packages globally.Try to do the following-

npm uninstall -g serve 
npm i -S serve

Let me know if this works.

Stipple answered 5/4, 2019 at 7:23 Comment(2)
this didn't work for me but npx serve didDoctorate
For those wondering like I did: the -S used to be the save option. It added the package to your dependencies. Now the -S has been removed. The install command adds the package by default. In case you don't want to save, use the --no-save option.Cadena
D
35

I had same problem too and this helped me to fix it so try this after installing serve;

 npx serve -s build 

or

npx serve -s build -p 8000  

(8000 = it depends by your choice) I don't know why but this worked for me

Deprecative answered 27/3, 2021 at 10:40 Comment(1)
This worked for me tooWessling
P
25

None of these above answers worked for me, so this is what works for me :

  • sudo su
  • npm install -g serve

Installing as root helps globally installing serve

Pains answered 6/1, 2021 at 17:3 Comment(1)
Nothing above worked for me but this one worked. Thanks!Mustard
L
20

Make sure to have this in your .bashrc or .zshrc

if you're using Yarn:

export PATH="$PATH:$(yarn global bin)"

if you're using NPM:

export PATH="$(npm bin -g):$PATH"

So that the shell would know where to look for executables such as serve, npx, live-server etc that are installed globally.

Make sure to reload your shell config:

source ~/.bashrc // or ~/.zshrc
Lawton answered 26/7, 2020 at 18:44 Comment(1)
This solution worked for me, even for other react components I had to do the same thing (Ubuntu)Walther
B
4

If anyone still gets the problem, try this:

npm uninstall -g serve
npm i -S serve
yarn global add serve
Bria answered 28/12, 2019 at 11:41 Comment(0)
P
4

I faced the same problem, what I did was run the command yarn serve -s build If you got it installed with npm then you can just add npm before the suggested command

Pneumonectomy answered 5/4, 2020 at 6:57 Comment(0)
C
0

you can use yarn serve ./dist replace serve ./dist

Cull answered 7/6, 2023 at 7:1 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Dunaway

© 2022 - 2024 — McMap. All rights reserved.