I am using as an environment, a Cloud9.io ubuntu VM Online IDE and I have reduced by troubleshooting this error to just running the app with Webpack dev server.
I l
Add this config to your webpack config file when using webpack-dev-server (you can still specify the host as 0.0.0.0).
devServer: {
disableHostCheck: true,
host: '0.0.0.0',
port: 3000
}
The problem occurs because webpack-dev-server
2.4.4 adds a host check. You can disable it by adding this to your webpack config:
devServer: {
compress: true,
disableHostCheck: true, // That solved it
}
EDIT: Please note, this fix is insecure.
Please see the following answer for a secure solution: https://stackoverflow.com/a/43621275/5425585
If you have not ejected from CRA yet, you can't easily modify your webpack config. The config file is hidden in node_modules/react_scripts/config/webpackDevServer.config.js
. You are discouraged to change that config.
Instead, you can just set the environment variable DANGEROUSLY_DISABLE_HOST_CHECK
to true
to disable the host check:
DANGEROUSLY_DISABLE_HOST_CHECK=true yarn start
# or the equivalent npm command
If you are running webpack-dev-server
in a container and are sending requests to it via its container name, you will get this error. To allow requests from other containers on the same network, simply provide the container name (or whatever name is used to resolve the container) using the --public
option. This is better than disabling the security check entirely.
In my case, I was running webpack-dev-server
in a container named assets
with docker-compose. I changed the start command to this:
webpack-dev-server --mode development --host 0.0.0.0 --public assets
And the other container was now able to make requests via http://assets:5000
.