Starting with React and Flux architecture but met some infrastucture troubles.
I can't access the web-page started by webpack-dev-server on the vagrant box (scotch-box). The command starts the application on localhost:3002, my vagrant box has an IP (192.168.33.10) address in Windows host machine and I can access it. But when I trying to access 192.168.33.10:3002 I'm getting the error: "Cant get access to the page...."
I checked that I have access to page from the vagrant box console curl http://localhost:3002
.
Does anyone have any ideas why that happens?
I'm also using the babel and presets for es2015 and react.
Here is the webpack config file:
module.exports = {
entry: "./src/js/main.js",
output: {
path: "./dist",
filename: "bundle.js",
publicPath: "/"
},
devServer: {
inline: true,
port: 3002,
contentBase: "./dist"
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: "babel",
query: {
presets: ["es2015", "react"]
}
}
]
}
};
And here is my package.json
{
"name": "flux-jenezis",
"version": "1.0.0",
"description": "Flux realisatoin usign egghead guide",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server"
},
"keywords": [
"flux",
"react"
],
"author": "jenezis",
"license": "ISC",
"dependencies": {
"flux": "^2.1.1",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-router": "^2.4.0"
},
"devDependencies": {
"babel-core": "^6.7.7",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0"
}
}
UPD: I can access different applications started by node server, and they accessable by 192.168.33.10:3002
UPD2: made network diagnostic using windows default tools, and the diagnose was: "Remote Device Won't Accept Connection"
Create an option, controlled by an environment variable (e.g. DEV_SERVER_STATIC=true ), which will disable webpack-dev-server and instead run webpack to compile assets to disk, then watch for changes in the filesystem, and run webpack again on-demand to re-compile as necessary.
Go to Task-Manager and close the task Node. js: Server-side JavaScript . Show activity on this post.
Answer : D) 8080 is the default where webpack-dev-server runs.
Found the solution. By default webpack-dev-server
runs the application on localhost:<port>
. To change it you can run the webpack-dev-server
using this command (by passing the --host option):
webpack-dev-server --port 3000 --hot --host 0.0.0.0
0.0.0.0
binds to all hosts.
I changed my package.json
and now it's look like:
{
"name": "flux-jenezis",
"version": "1.0.0",
"description": "Flux realisatoin usign egghead guide",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --host 0.0.0.0"
},
"keywords": [
"flux",
"react"
],
"author": "jenezis",
"license": "ISC",
"dependencies": {
"flux": "^2.1.1",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-router": "^2.4.0"
},
"devDependencies": {
"babel-core": "^6.7.7",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0"
}
}
For those who may still have this problem, like I did, the issue for me was with the port-forwarding. My Virtualbox VM is a linux VM with an apache web server on it. I use Vagrant to easily spin up my VM with a config file, Vagrant calls these a 'Vagrantfile'. In the 'Vagrantfile' you can specify ports you want forwarded between the guest machine (your VM) and the host machine (your actual OS).
This looks something like this:
config.vm.network "forwarded_port", guest: 3000, host: 3000
When the VM spins up , that port(s) will now be accessible from your guest machine on your host machine. In other words, if your webpack config looks like this:
devServer: {
host: '0.0.0.0',
port: 3000
}
You should now be able to visit http://0.0.0.0:3000
from your browser on your host machine.
Note: If you're using Virtualbox but not Vagrant and you still need help with port-forward, visit this article for some good tips: https://blog.codecentric.de/en/2017/08/fix-webpack-watch-virtualbox/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With