Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory error with crawl mode #116

Open
astrotim opened this issue Oct 6, 2017 · 1 comment
Open

Memory error with crawl mode #116

astrotim opened this issue Oct 6, 2017 · 1 comment

Comments

@astrotim
Copy link

astrotim commented Oct 6, 2017

I am getting a "JavaScript heap out of memory" error when running a build with crawl: true. Here is the console output

<--- Last few GCs --->

[88328:0x103800000]   371328 ms: Mark-sweep 1402.1 (2063.0) -> 1402.0 (2052.5) MB, 125.9 / 0.0 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 127 ms) last resort 
[88328:0x103800000]   371463 ms: Mark-sweep 1402.0 (2052.5) -> 1401.8 (2052.0) MB, 134.4 / 0.0 ms  last resort 


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x1c73bc09bbd9 <JS Object>
    1: /* anonymous */ [.../node_modules/static-site-generator-webpack-plugin/index.js:88] [pc=0x502f8d5fb66](this=0x2690e5c8a1e1 <JS Global Object>,key=0xf0700a8dc39 <Very long string[45664]>)
    2: arguments adaptor frame: 3->1
    3: map [native array.js:~832] [pc=0x502f91c16c7](this=0x395e0fd11431 <JS Array[1]>,bd=0x395e0fd11451 <JS Function (SharedFunctionI...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/Users/xxx/.nvm/versions/node/v8.2.1/bin/node]
...

If I disable crawl mode, the build works, but obviously I don't get all my static pages generated.

Node 8.2.1
webpack 2.6.1
static-site-generator-webpack-plugin 3.4.1

The app works normally when I build it as a purely client app using webpack-dev-server.

Is there any way to debug why this is causing the memory error?


This is my full Webpack config

const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');

let plugins = [
  new ExtractTextPlugin('style.css'),
  new StaticSiteGeneratorPlugin({
    crawl: true,
    paths: ['/']
  }),
  new CopyWebpackPlugin([
    {
      from: path.resolve(__dirname, 'src', 'favicon.ico'),
      to: path.resolve(__dirname, 'dist')
    },
    {
      from: path.resolve(__dirname, 'fonts'),
      to: path.resolve(__dirname, 'dist', 'fonts')
    }
  ]),
  new webpack.DefinePlugin({
    'process.env': {
      NODE_ENV: JSON.stringify('production')
    }
  }),
  new webpack.optimize.UglifyJsPlugin()
];

if (process.env.ANALYZE_WEBPACK) {
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
    .BundleAnalyzerPlugin;

  plugins.push(
    new BundleAnalyzerPlugin({
      openAnalyzer: false
    })
  );
}

module.exports = {
  entry: {
    bundle: path.resolve(__dirname, 'src')
  },

  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js',
    libraryTarget: 'umd'
  },

  plugins: plugins,

  // exclude
  externals: {
    'babel-standalone': 'babel-standalone'
  },

  module: {
    rules: [
      {
        test: /\.js$/,
        include: [path.resolve(__dirname, 'src')],
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['react', 'es2015']
          }
        }
      },
      {
        test: /\.(css|scss)$/,
        loader: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            {
              loader: 'css-loader',
              options: {
                modules: true,
                camelCase: true,
                localIdentName: '[name]__[local]--[hash:base64:5]'
              }
            },
            {
              loader: 'postcss-loader',
              options: {
                plugins: [require('autoprefixer')]
              }
            },
            {
              loader: 'sass-loader'
            }
          ]
        })
      }
    ]
  }
};
@astrotim
Copy link
Author

astrotim commented Oct 6, 2017

I've narrowed this down to an issue with some markdown. I am using a package called marsky to compile markdown into a React tree, but this compilation makes the build hang when I have crawl: true.

The function is

const getMarkup = markdown => {
  if (!markdown) return null;
  console.log('getMarkup', markdown);
  const compile = marksy({
    createElement,
    elements: {}
  });
  return compile(markdown).tree;
};

// invoked as 
{getMarkup(someMarkdown)}

I can see the function call being logged infinitely in the console in crawl mode, but it's fine otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant