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.
-
it should work, can you try to uninstall and reinstall it using npm? – Vinay Pandya Apr 05 '19 at 07:09
-
Still doesn't work. But I managed to install it locally (only to my project folder) with npx – Roland Apr 05 '19 at 07:18
-
okay you can may be change global installation for node_module ref: https://stackoverflow.com/questions/5926672/where-does-npm-install-packages may be this can help you out – Vinay Pandya Apr 05 '19 at 07:19
7 Answers
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.

- 1,434
- 4
- 29
- 53
-
7
-
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. – João Souza Mar 31 '23 at 19:58
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

- 301
- 3
- 6
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

- 626
- 5
- 12
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

- 2,825
- 1
- 20
- 34
-
1This solution worked for me, even for other react components I had to do the same thing (Ubuntu) – Fernando Tholl Dec 02 '20 at 12:41
If anyone still gets the problem, try this:
npm uninstall -g serve
npm i -S serve
yarn global add serve

- 454
- 1
- 4
- 11
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

- 41
- 1
you can use yarn serve ./dist replace serve ./dist

- 1
- 1
-
1Your 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](/help/how-to-answer). – Community Jun 07 '23 at 16:15