Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-js project Deployment failed. "serve" is not recognized as an internal or external command

Facing Problem in Deploying a React-js Application on windows server

  • I installed serve globally by npm install -g serve command
  • serve -s build is not running
  • "Serve" is not recognized as an internal or external command

I have successfully build the react Application. I am a bit confused what to do after build. serve is not working. also please answer what to do with server.js file in react project and how it helps in deployment

my application is running properly on local. I want it to run on my domain also.

npm serve is installed globally please click here to see the image

like image 253
Rahul Kumar Avatar asked Apr 23 '19 16:04

Rahul Kumar


People also ask

How do you fix react-scripts is not recognized as an internal or external command?

To solve the error "react-scripts is not recognized as an internal or external command, operable program or batch file", open your terminal in your project's root directory and install the react-scripts package by running npm install react-scripts and clear your npm cache if necessary. Copied!

How do you enable JavaScript in react JS?

In the “Settings” section click on the “Show advanced settings” Under the the “Privacy” click on the “Content settings”. When the dialog window opens, look for the “JavaScript” section and select “Allow all sites to run JavaScript (recommended)”. Click on the “OK” button to close it.

How do you serve a react app?

For your React app, you'll have to drag and drop the build folder onto the Netlify Dashboard. Run npm run build beforehand to deploy the latest build. You can also connect GitHub, GitLab, or Bitbucket, depending on where your project is stored. This allows automatic deployment whenever you push your changes.


1 Answers

I know that running npx serve -s build should work. I had the same problem as you. The npx command works for me. If you have npx problems, check your version of nodejs. I'm running 10.16.2 (so that we're on the same page). https://www.npmjs.com/package/serve

The rest of your question is relative to the rest of your set up. I don't have a server.js file of my own (there are some node_module server.js files, is that what you mean)?

As I understand a create-react-app, npm run start will allow you to run your application locally. I don't need serve -s build for that.

I used an amplify create react app. For an amplify application, I just run amplify publish and my application's build directory is sent to an S3 bucket for me. If you don't have that configuration, and you want the quick and dirty answer... just take the contents of your build directory in your react application and drop those files on your web server. That should get you 90% of the way there (mind the default page that renders).

like image 164
Dan Avatar answered Sep 27 '22 23:09

Dan