Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 http://localhost:3333 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: enter image description here

Edit: My package.json:

{
  "name": "react-app",
  "version": "1.0.0",
  "description": "sample",
  "scripts": {
    "start": "webpack-dev-server"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/dheeraja00/react-app.git"
  },
  "author": "Dheeraj Agrawal",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/dheeraja00/react-app/issues"
  },
  "homepage": "https://github.comdheeraja00/react-app#readme",
  "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"
  }
}
like image 806
Dheeraj Agrawal Avatar asked Nov 08 '16 03:11

Dheeraj Agrawal


People also ask

How do I start an npm local server?

You can provide port number and custom test command, in that case npm start is assumed to start the server. or for multiple ports simply: server-test '8000|9000' test . The above script ci after the localhost:9000 responds executes the npm run test:unit command. Then when it finishes it runs npm run test:e2e .

Why is my npm start not working?

Check the ignore-script config If you see the start script is present inside your package. json file but still can't run the script, you need to check the console output. If there's no output at all, then you may have the ignore-scripts npm configuration set to true .

Is npm start same as NG serve?

Basically npm start and ng serve can be used interchangeably in Angular projects as long as you do not want the command to do additional stuff.


2 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
like image 168
Deepak Kumrawat Avatar answered Oct 23 '22 14:10

Deepak Kumrawat


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.

like image 26
AJS Avatar answered Oct 23 '22 12:10

AJS