1

While starting a react app via npm start in Vultr I am getting below an error : Could anyone please advise what is causing this error. I am not getting the error in my local system.

root@automateandmore:~/automatemore# npm start

vinmatblogs@0.1.0 start react-scripts start

Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
 - options.allowedHosts[0] should be a non-empty string.
Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54
soccerway
  • 10,371
  • 19
  • 67
  • 132

1 Answers1

0

You can build a React project and publish it with Nginx directly on a Vultr VPS. So you don't need to run any nodejs server.

For this, you need to specify the path of the build file created with the npm build command in the nginx configuration.

As for your question, if for some reason you want to publish your site in development mode by running nodejs server with the npm start command; you can add the following to the package.json file.

"devServer": {
     "allowedHosts": "all"
   }

With this code, you allow the running nodejs server to be accessed from any device. Don't forget to run it again with npm start after making this addition.

I also recommend to read this answer: https://stackoverflow.com/a/47505427/14893142

nevidev
  • 93
  • 1
  • 8
  • How can I access the nginx configuration and `specify the path of the build file created with the npm build command in the nginx configuration` as you mentioned – soccerway Apr 16 '23 at 10:16
  • @soccerway It depends. One way is that you'll create a file in /etc/nginx/sites-available/ directory. Put some info in that file with the path of your build folder as root statement. Then you'll link that file to /etc/sites-enabled/ folder. Then you'll restart nginx server. Here are some links for detailed information: https://stackoverflow.com/a/52714450/14893142 https://stackoverflow.com/questions/52713902/using-nginx-with-react-js https://www.youtube.com/watch?v=3dIVesHEAzc – nevidev Apr 16 '23 at 17:53