Why is 'document' is not defined error on webpack build?

Viewed 7205

I am preparing to put a small react app on Heroku and am working on a production config. When I run npm run build all works. However, when I got to run the built file node dist/dist.js I receive the error:

ReferenceError: document is not defined

Should I be using a different css loader? My webpack.deployment.config.js is as follows:

    const path = require('path');
const webpack = require('webpack');

module.exports = {
  devtool: 'source-map',

  entry: [
    './client/index.js'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: './dist/'
  },
  plugins: [
    new webpack.optimize.UglifyJsPlugin({
      minimize: true,
      compress: {
        warnings: false
      },
      sourceMap: true
    })
  ],
  module: {
    loaders: [{
      test: /.jsx?$/,
      loader: 'babel-loader',
      include: path.join(__dirname, 'client'),
      exclude: /node_modules/,
      query: {
        presets: ['es2015', 'react']
      }
    },
     { test: /\.css$/, loader: "css-loader" },
     { test: /\.(jpg|png|svg)$/, use: 'file-loader'}

    ]
  },
};
1 Answers

The npm module jsdom can be used to make window and document available in non-browser environments.

Related