Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack Uglify plugin returns "Killed" on Ubuntu

Tags:

gulp

webpack

On my remote server (Ubuntu 14.04 x64), whenever I try to uglify my bundles, the process simply returns "Killed". When I don't uglify, it's just fine.

Has anyone run into this? When I do it on my local Mac, it's fine (although I just tested it and it took 1.4 mins).

This is my webpack.config:

var webpack = require('webpack');

function makeConfig(opts) {
    var config = {

        entry: {
            app: ['./public/scripts/main.js'],
            vendor: ['lodash', 'react', 'react/lib/ReactCSSTransitionGroup', 'react-router', 'reqwest', 'd3']
        },

        stats: {
            colors: true,
            reasons: true
        },

        output: {
            devtool: (opts.env === 'dev' ? '#eval-source-map' : ''),
            path: 'dist/scripts',
            filename: '[name].bundle.js'
        },

        plugins: [
            new webpack.DefinePlugin({
                ENV: opts.env
            }),
            new webpack.optimize.CommonsChunkPlugin('vendor.bundle.js')
        ],

        module: {
            loaders: [
                { test: /\.jsx?$/, loader: 'jsx-loader' }
            ]
        }
    };

    if(opts.env === 'prod') {
        config.plugins.push(
            new webpack.optimize.UglifyJsPlugin(),
            new webpack.optimize.DedupePlugin()
        );
    }

    return config;
}

module.exports = makeConfig;

and it's called by gulp like so:

gulp.task('webpack', ['cleanScripts'], function(done) {
    webpack(webpackConfig, function(err, stats) {
        if(err) {
            console.error(err);
            throw new gutil.PluginError('webpack', err);    
        }
        else {
            done();
        }
    });
});
like image 471
ccnokes Avatar asked Jun 10 '15 04:06

ccnokes


3 Answers

As @barbuza suggested, it was a memory issue. I too am using a Digital Ocean VPS that only has 512 MB of RAM (yes, I'm cheap). That's not enough for webpack's uglify plugin. Adding 2GB of swap space on the server solved the issue. I followed this article to set that up: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

like image 127
ccnokes Avatar answered Oct 21 '22 14:10

ccnokes


Same thing happened with me while Digital Ocean VPS using, as mentioned above - that happens because of building takes to much RAM for your machine, so it's "out of memory usage".

To solve this you can minimize RAM usage while file compiling via ---max_old_space_size option, here is an advanced example of usage

node --max_old_space_size=1096 node_modules/webpack/.bin/webpack.js

Of course you can choose any size, also you can do the same with webpack-dev-server. And you don't need to add the swap space until it will be really needed for other purposes, such as you run this command only once to compile the bundle.js file.

like image 40
Purkhalo Alex Avatar answered Oct 21 '22 16:10

Purkhalo Alex


I had the same issue on digital ocean vm, it turned out there was no swap configured, so it just run out of memory.

like image 1
Victor Kotseruba Avatar answered Oct 21 '22 15:10

Victor Kotseruba