Npm Start Not Starting Local Server

Npm Start Not Starting Local Server

I am trying to make an react app using webpack and when I try to run npm start it should load but it says site cannot be reached, here is my webpack config:

module.exports = {
    entry: './main.js',
    output: {
        path: '/',
        filename: 'index.js'
    },
    devServer: {
        inline: true,
        port: 3333
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'react']
                }
            }
        ]
    }
}

And here is my script object from package.json: "start": "webpack-dev-server". I have already installed webpack & webpack-dev-server globally. Check below image which I am getting:

Edit: My package.json:

{
  "name": "react-app",
  "version": "1.0.0",
  "description": "sample",
  "scripts": {
    "start": "webpack-dev-server"
  },
  "repository": {
    "type": "git",
    "url": "git+"
  },
  "author": "Dheeraj Agrawal",
  "license": "ISC",
  "bugs": {
    "url": ""
  },
  "homepage": "",
  "dependencies": {
    "material-design-lite": "^1.2.1",
    "react": "^15.3.2"
  },
  "devDependencies": {
    "babel-core": "^6.18.0",
    "babel-loader": "^6.2.5",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-react": "^6.16.0",
    "css-loader": "^0.25.0",
    "file-loader": "^0.9.0",
    "node-sass": "^3.10.1",
    "raw-loader": "^0.5.1",
    "sass-loader": "^4.0.2",
    "style-loader": "^0.13.1",
    "webpack": "^1.13.2",
    "webpack-dev-server": "^1.16.2"
  }
}
7

5 Answers

You can run any one of the below mentioned commands to start the node server for your reactJs application:

 npm run-script start
 npm run start
 npm start

npm start will only work when you have a start script.

For the below example webpack-dev-server and webpack packages are required. To add these packages you should install webpack-dev-server and webpack globally.

npm install webpack-dev-server webpack -g

For Example:

"scripts": {
    "start": "webpack-dev-server"
 }

in you package.json, basically when you run npm start it searches your package.json for what to do.

8

Instead of Trying URL:
Try URl:

And, if works fine.
Then for a permanent fix try adding an entry to /etc/hosts file as if it doesn't exist or commented

127.0.0.1 localhost

Answering as this happened to me with a new installation of Ubuntu 18.04 where localhost did not exist in my hosts file and had to be added.

You can check if this is your issue by navigating the browser to 127.0.0.1:3333 instead. If it is available you need to add the following line to your /etc/hosts file

127.0.0.1 localhost

you need a global version of webpack and then run script again.

    use: 

If this is still not working then change port or stop services running on this port

Your Answer

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

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.