Npm Command 'Serve ' Not Found, Although It Is Installed

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.

3

6 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

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
1

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

1

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

1

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

If anyone still gets the problem, try this:

npm uninstall -g serve
npm i -S serve
yarn global add serve

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest