To fix the “Invalid Host header” message when connecting to the webpack-dev-server remotely error, use the environment variable “DANGEROUSLY_DISABLE_HOST_CHECK=true” to disable the host check. This method is more straightforward and doesn’t require editing the webpack configuration file.
“Invalid Host header” message when connecting to webpack-dev-server remotely error occurs when you are “trying to access the server remotely using an IP address or hostname that’s not authorized in the configuration.”
Here are the steps to fix the error in your program:
- Create a “.env” file in the root directory of your project.
- Add the following line to the “.env” file:
DANGEROUSLY_DISABLE_HOST_CHECK=true
- Restart your webpack-dev-server to apply the change.
This approach is suitable for development environments where you may need to access the server from various hostnames or IP addresses.
However, it’s essential to understand that this setting can expose your application to security risks. It should never be used in a production environment or with sensitive data.
For projects created with Create React App (CRA), the webpack configuration is hidden by default, and using “npm run eject” to expose it is often considered an irreversible and potentially risky operation. It can lead to difficulties in maintaining and updating the project in the future.
This approach allows for flexibility without injecting and directly manipulating the underlying webpack configuration, keeping the project maintainable and aligned with CRA’s best practices.
Other common reasons for the error
Misconfigured proxy settings
Misconfigured proxy settings can cause issues, including the “Invalid Host header” error or other connectivity problems in a development environment like Create React App (CRA) with webpack-dev-server.
Here’s how you can identify and fix some common proxy misconfigurations:
- Check Your Proxy Configuration
- CORS Issues
- Using Advanced Proxy Configuration
- Check the Backend Server
- Revert to Defaults
Incorrectly configured DNS settings
Incorrectly configured DNS (Domain Name System) settings can lead to various issues, including the “Invalid Host header” error, inability to resolve hostnames or other connectivity problems.
Here are some common scenarios and solutions to address issues related to DNS misconfigurations:
- DNS Resolution Issues
- Incorrect DNS Records
- Local Hosts File Misconfiguration
- Webpack-dev-server Specific Configuration
- Network Configuration
Incorrect Hostname in Webpack Dev Server’s Configuration
An incorrect hostname in the webpack-dev-server’s configuration can lead to an “Invalid Host header” error. This error occurs when the requested host in the HTTP request doesn’t match the allowed hosts in the webpack-dev-server’s configuration.
Here’s how you can address this issue:
- Identify the Correct Hostname.
- Update the Configuration
- Restart the Development Server
- Check Your Request
Common solutions
Modify Webpack Configuration (Not recommended)
You can update your webpack-dev-server configuration to specify the allowed host(s).
Here are two common ways to do this:
Approach 1: Allowing Any Host (not recommended for production)
You can disable the host check altogether by setting the disableHostCheck property to true. This can be useful for development purposes but is not secure for a production environment.
// webpack.config.js
module.exports = {
// ...
devServer: {
disableHostCheck: true,
// ...
},
// ...
};
Specifying Allowed Hosts
You can list the allowed hosts in the allowedHosts array. This method is more secure as you specify precisely which hosts are permitted.
// webpack.config.js
module.exports = {
// ...
devServer: {
allowedHosts: ['host.com', 'another-host.com'],
// ...
},
// ...
};
Set the Public Host
You can also use the public option to specify the public host and port.
// webpack.config.js
module.exports = {
// ...
devServer: {
public: 'your-public-url.com:8080',
// ...
},
// ...
};
Restart webpack-dev-server
After making these changes, restart the webpack-dev-server to apply the new configuration.
Related posts
Field ‘browser’ doesn’t contain a valid alias configuration
TypeError: this.getOptions is not a function
Cannot find module ‘webpack/bin/config-yargs’

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.