Webpack-dev-server: Node js API => Uncaught SyntaxError: The URL 'http:/sockjs-node' is invalid

Created on 16 Sep 2017  路  1Comment  路  Source: webpack/webpack-dev-server

  • Operating System: OS X 10.11.6
  • Node Version: 8.4.0
  • NPM Version: 5.4.2
  • webpack Version: 3.6.0
  • webpack-dev-server Version: 2.8.2

  • [ ] This is a feature request

  • [ x] This is a bug

Code

  // server.js

const path = require('path')
const webpackDevServer = require('webpack-dev-server')
const webpack = require('webpack')
const config = require('./webpack.config.js')

const options = {
//hot: true,
publicPath: path.resolve(__dirname, '/dist'),
};

webpackDevServer.addDevServerEntrypoints(config, options);
const compiler = webpack(config)

const server = new webpackDevServer(compiler, options);
server.listen(8080, 'localhost', function (err, result) {
if (err) {
return console.log(err);
}
});

Expected Behavior

HMR available

Actual Behavior

error in devTools console :
Uncaught SyntaxError: The URL 'http:/sockjs-node' is invalid
at new SockJS (bundle.js:18255)
at socket (bundle.js:16709)
at Object. (bundle.js:14895)
at Object. (bundle.js:14921)
at __webpack_require__ (bundle.js:678)
at fn (bundle.js:88)
at Object. (bundle.js:14686)
at __webpack_require__ (bundle.js:678)
at module.exports.ctor.super_ (bundle.js:724)
at bundle.js:727

Most helpful comment

Found it : be sure to add options 'port' and 'host' :
`
const options = {
hot: true,
publicPath: path.resolve(__dirname, '/dist'),
port: port,
host: 'localhost',
};

webpackDevServer.addDevServerEntrypoints(config, options);
`

>All comments

Found it : be sure to add options 'port' and 'host' :
`
const options = {
hot: true,
publicPath: path.resolve(__dirname, '/dist'),
port: port,
host: 'localhost',
};

webpackDevServer.addDevServerEntrypoints(config, options);
`

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gimmi picture gimmi  路  3Comments

daryn-k picture daryn-k  路  3Comments

antoinerousseau picture antoinerousseau  路  3Comments

movie4 picture movie4  路  3Comments

eyakcn picture eyakcn  路  3Comments