question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

global is undefined? unable to start RHL

See original GitHub issue

I have an express server that serves my html from :3111. I also start a webpack dev server (copied from https://github.com/gaearon/react-hot-boilerplate/blob/master/server.js) on :3000. in my html, I load localhost:3000/script.js

// webpack.config.js
var webpack = require('webpack'),
  path = require('path');

module.exports = {
  devtool: 'eval',
  target: 'web',
  entry: [
    'webpack-dev-server/client?http://0.0.0.0:3000', // WebpackDevServer host and port
    'webpack/hot/only-dev-server',
    './editor/index.js'
  ],
  output: {
    path: path.join(__dirname, 'public'),
    filename: 'editor.js',
    publicPath: '/'
  },
  module: {
    loaders: [{
      test: /\.js$/,
      // exclude: /node_modules/,
      loaders: ['react-hot', 'envify-loader', 'babel-loader']
    }]
  },
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ]
};

// server.js
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
var wconfig = require('./webpack.config');

new WebpackDevServer(webpack(wconfig), {
  publicPath: wconfig.output.publicPath,
  hot: true,
  historyApiFallback: true
}).listen(3000, 'localhost', err => console.log(err || 'webpack at localhost:3000'));

It seems to compile alright

When I start the app, it bails almost immediately, saying Uncaught TypeError: Cannot read property 'WebSocket' of undefined (because global is undefined)

Anything I need to do on my express server/html to make this work?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, May 15, 2015

You’ll want to uncomment exclude: /node_modules/, because some of the scripts used by hot module replacement machinery will not work with Babel out of the box.

0reactions
smondalcommented, Jul 6, 2017

Set the valid target thing for webpack.

module.exports = {
  // ...

  target: 'node',
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

1905419 – global registration fails with ERROR
Summary: global registration fails with ERROR: undefined method '#login' for NilClass:... Keywords: Reopened, Triaged. Status: CLOSED NOTABUG.
Read more >
unknown error: Chrome failed to start: exited abnormally ...
It is failing to start due to a mismatch between the chrome version and the chromedriver version. Downloading and installing the same versions ......
Read more >
Server Connector - Visual Studio Marketplace
A Visual Studio Code extension for interacting with Red Hat Servers and Runtimes. Commands and features. screencast. This extension depends on ...
Read more >
Error while building host using `PXEGrub2 global default ...
Rendering the template fails with: "Unable to render PXEGrub2 template 'PXEGrub2 global default': undefined method `each' for nil:NilClass".
Read more >
Network Debug and Troubleshooting Guide
The unable to open shell message means that the ansible-connection daemon has not been able to successfully talk to the remote network device....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found