Comments (15)
I also have this issue. My server setup looks like this:
var path = require('path');
var express = require('express');
var webpack = require('webpack');
var config = require('./webpack.local.config');
var port = process.env.PORT || config.devPort;
var address = config.devAddress;
var app = express();
var compiler = webpack(config);
// Logging
app.use(require('morgan')('short'));
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'app/local.html'));
});
app.use(require('webpack-hot-middleware')(compiler));
app.listen(port, address, function (error) {
if (error) throw error;
console.log('server running at http://%s:%d', address, port);
});
EDIT:
I changed my config to this and it worked.
var path = require('path');
var express = require('express');
var webpack = require('webpack');
var config = require('./webpack.local.config');
var port = process.env.PORT || config.devPort;
var address = config.devAddress;
var app = express();
var compiler = webpack(config);
// Logging
app.use(require('morgan')('short'));
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler, {
log: console.log,
path: '/__webpack_hmr',
heartbeat: 10 * 1000
}));
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'app/local.html'));
});
app.listen(port, address, function (error) {
if (error) throw error;
console.log('server running at http://%s:%d', address, port);
});
from webpack-hot-middleware.
I had this error while serving a static index.html (using Express static middleware), and including my js bundle as a script there. As my first webpack entry, I had
'webpack-hot-middleware/client?path=http://localhost:3000/
It started working when I changed it to
'webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr',
from webpack-hot-middleware.
Yep, the webpack-hot-middleware
middleware needs to come before the wildcard *
handler so it can match the path.
from webpack-hot-middleware.
The /__webpack_hmr
is a GET
request, which means when you do app.get('*')
, then you send the HTML along with webpack-hot-middleware
.
Fix it by adding route /__webpack_hmr
as an exception in app.get('*')
.
app.get('*', (req, res) => {
if (req.url === "/__webpack_hmr")
return;
//html handling here
});
from webpack-hot-middleware.
from webpack-hot-middleware.
For me it is coming when I upgraded nuxt 2 to use nuxt-bridge
This request is firing again n again, resulting in the same error.
Anyone can help?
from webpack-hot-middleware.
Are you re-setting the req.url
at any point? I was using the HtmlWebpackPlugin
to generate my index.html file which caused some issues with the webpack middleware. The suggested fix was to set the req.url
to simply just req.url = '/'
when not one of my static or webpack middleware routes. One thing I also needed to do was to make sure i allow the url '/__webpack_hmr'
to reach the webpack middleware as well so that socket can be established. I guess a hacky way would to do something like this:
// Import configs and whatever
// ...
app.get('/*', (req, res, next) => {
if (!req.url.match('static') && !req.url.match('/__webpack_hmr') && !req.url.match('bundle.js')) {
req.url = '/';
}
next();
});
// Webpack stuff
const compiler = webpack(config);
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath,
}));
app.use(require('webpack-hot-middleware')(compiler));
// Static files
app.get('/static/*', (req, res) => {
res.sendFile(path.join(__dirname, req.url));
});
const PORT = 8080;
app.listen(PORT, '0.0.0.0', (err) => {
if (err) {
throw err;
}
console.log(`The magic happens on port ${PORT}!`); // eslint-disable-line no-console
});
I would suggest something more eloquent but I am not really sure what your express app file looks like to suggest something better!
from webpack-hot-middleware.
The
/__webpack_hmr
is aGET
request, which means when you doapp.get('*')
, then you send the HTML along withwebpack-hot-middleware
. Fix it by adding route/__webpack_hmr
as an exception inapp.get('*')
.app.get('*', (req, res) => { if (req.url === "/__webpack_hmr") return; //html handling here });
Instead of only returning, I needed to force the response type to "text/event-stream":
app.get("*", (req, res) => {
if(req.url == "/myreverseproxy/__webpack_hmr") {
res.type('text/event-stream');
return;
}
res.sendFile(path.resolve(__dirname, "..", "public", "index.html"));
});
from webpack-hot-middleware.
Have you reconfigured the paths at all? Are you using an intermediary proxy?
Can you show the output of the network tab?
This error means the event stream URL is incorrectly claiming to be HTML for some reason
from webpack-hot-middleware.
The same error occurred to me when i did not set the content-type
for the file, so just make sure you're setting the content-type for the file.
from webpack-hot-middleware.
The same problem, i configure https proxy via nginx
from webpack-hot-middleware.
meet the same question. and I use the nginx proxy. still have no way.
from webpack-hot-middleware.
It works only I add this line in the entry of webpack.
'index': [
'webpack-hot-middleware/client?path=http://localhost:'+siteConfig.port+'/__webpack_hmr', //this line
'./js/index'
]
from webpack-hot-middleware.
@devarsh What did you set the content-type as?
from webpack-hot-middleware.
Commenting out "webpack-hot-middleware/client" in my webpack.config.js solved this for me
Funnily enough this solved it for me as well. This is likely due to the fact that the webpack-hot-middleware
plugin is getting instantiated somewhere else.
from webpack-hot-middleware.
Related Issues (20)
- TypeError: cb is not a function HOT 1
- error TS2339: Property 'compilers' does not exist on type 'Compiler'. HOT 1
- Which package to use on a Deno server? HOT 1
- `webpack-hot-middleware/client?reload=true` is no longer working with webpack 5. HOT 36
- not work on webpack5 HOT 7
- Overlay is not working with Webpack 5 HOT 4
- Ignored an update to unaccepted module - No automatic page reloading with recent versions of webpack and react packages HOT 3
- Types are broken with Webpack 5 HOT 3
- `module.hot` is required ?
- enable use of other backends besides express
- when updating the example everything will break please update HOT 4
- ReDoS Vulnerability HOT 2
- Replace deprecated querystring component with builtin URLSearchParams API HOT 8
- Overlay is invalid in webpack5. Haven't you solved it yet? How long do you plan to publish it to the master? I hope you can reply
- Hot Updates not being handled by server HOT 2
- Opening 5+ tabs causes Express to hang indefinitely HOT 2
- webpack-hot-server-middleware on demand loading bug
- webpackv5 webpack-hot-server-middleware Compatibility problems HOT 1
- A Chrome specific issue, where requests are getting blocked after a handful of link clicks HOT 3
- Webpack 5: incorrect compilation error text output starting with "undefined undefined" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpack-hot-middleware.