Reputation: 2357
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:
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"
}
}
Upvotes: 8
Views: 91365
Reputation: 1104
Instead of Trying URL: http://localhost:3333
Try URl: http://127.0.0.1:3333
And, if http://127.0.0.1:3333 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
Upvotes: 2
Reputation: 33
you need a global version of webpack and then run script again.
use: https://127.0.01:3333
If this is still not working then change port or stop services running on this port
Upvotes: 0
Reputation: 2023
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.
Upvotes: 4
Reputation: 3320
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
Upvotes: 0
Reputation: 91
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
Upvotes: 4