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

JavaScript heap out of memory #372

Open
quentincaffeino opened this issue Apr 30, 2020 · 5 comments
Open

JavaScript heap out of memory #372

quentincaffeino opened this issue Apr 30, 2020 · 5 comments

Comments

@quentincaffeino
Copy link

How do we reproduce the issue?

We'll likely need to know:

  1. Your Rollup configuration.
import svelte from 'rollup-plugin-svelte'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import livereload from 'rollup-plugin-livereload'
import { terser } from 'rollup-plugin-terser'
import postcss from 'rollup-plugin-postcss'
import autoPreprocess from 'svelte-preprocess'
import copy from 'rollup-plugin-cpy'
import replace from '@rollup/plugin-replace'
import babel from 'rollup-plugin-babel'
import visualizer from 'rollup-plugin-visualizer';
import compiler from '@ampproject/rollup-plugin-closure-compiler';
import rimraf from 'rimraf'

rimraf('./public/js', {}, () => console.log('removed public/js'))
require('dotenv').config();


const production = !process.env.ROLLUP_WATCH;


function getOutput(production) {
    let output = {
        dir: "public/js/module",
        format: "es",
        sourcemap: !production,
        chunkFileNames: '[name].js'
    };

    if (production) {
        output = [
            output,
            {
                dir: "public/js/nomodule",
                format: "system",
                chunkFileNames: '[name].js'
            }
        ]
    }

    return output
}


function getReplacePlugin() {
    return replace({
        values: {
            'process.env.NODE_ENV': production ? '\"production\"' : '\"development\"',
            ENV_IS_PROD: production,
            PROD_BASEPATH: process.env.PROD_BASEPATH,
            API_ENDPOINT: process.env.API_ENDPOINT,
            MOCK_API: process.env.MOCK_API
        },
        exclude: './node_modules/**'
    })
}


function getPlugins(additionalPlugins = []) {
    return [
        getReplacePlugin(),

        babel({
            extensions: ['.ts', '.js'],
            exclude: './node_modules/**'
        }),

        // If you have external dependencies installed from
        // npm, you'll most likely need these plugins. In
        // some cases you'll need additional configuration -
        // consult the documentation for details:
        // https://github.com/rollup/plugins/tree/master/packages/commonjs
        resolve({
            browser: true,
            dedupe: ['svelte']
        }),
        commonjs({ extensions: ['.js', '.ts'] }),

        ...additionalPlugins,

        // If we're building for production (npm run build
        // instead of npm run dev), minify
        production && terser()
    ]
}


export default [
    {
        input: 'src/main.ts',
        output: getOutput(production),
        plugins: getPlugins([
            svelte({
                preprocess: autoPreprocess({
                    postcss: true
                }),
                // enable run-time checks when not in production
                dev: !production,
                // we'll extract any component CSS out into
                // a separate file - better for performance
                css: css => {
                    css.write('public/css/app.css');
                }
            }),

            copy([
                { files: './src/manifest.json', dest: './public' },
                { files: './src/assets/images/**/*', dest: './public/images' }
            ]),

            postcss({
                extract: 'public/css/vendor.css',
                minimize: production,
                sourceMap: !production,
            }),

            !production && visualizer({
                filename: './public/visualizer.html'
            }),

            // In dev mode, call `npm run start` once
            // the bundle has been generated
            !production && serve(),

            // Watch the `public` directory and refresh the
            // browser on changes when not in production
            !production && livereload({
                watch: 'public',
            }),

            production && compiler()
        ]),
        manualChunks(id) {
            if (id.includes('zxcvbn')) {
                return;
            }

            if (id.includes('node_modules')) {
                return 'vendor';
            }
        }
    }
];

function serve() {
    let started = false;

    return {
        writeBundle() {
            if (!started) {
                started = true;

                require('child_process').spawn('yarn', ['serve', '--', '--dev'], {
                    stdio: ['ignore', 'inherit', 'inherit'],
                    shell: true
                });
            }
        }
    };
}
  1. Error logs from your console when invoking Rollup with this plugin present.
<--- Last few GCs --->

[26287:0x41b2970]   110310 ms: Mark-sweep 2048.0 (2053.8) -> 2047.5 (2054.3) MB, 2074.6 / 0.0 ms  (+ 45.0 ms in 11 steps since start of marking, biggest step 12.8 ms, walltime since start of marking 2337 ms) (average mu = 0.112, current mu = 0.093) alloca[26287:0x41b2970]   112686 ms: Mark-sweep 2048.5 (2054.3) -> 2048.3 (2055.0) MB, 2232.3 / 0.0 ms  (+ 65.5 ms in 15 steps since start of marking, biggest step 11.4 ms, walltime since start of marking 2376 ms) (average mu = 0.072, current mu = 0.033) alloca

<--- JS stacktrace --->

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

    0: ExitFrame [pc: 0x13c03d9]
    1: StubFrame [pc: 0x136f7a6]
    2: StubFrame [pc: 0x1423fcb]
Security context: 0x0e139eac08d1 <JSObject>
    3: enter [0x1d5b63285651] [/home/.../node_modules/@ampproject/rollup-plugin-closure-compiler/dist/index.js:1] [bytecode=0x878d4e4db89 offset=6](this=0x1d5b63285b51 <Object map = 0x3c4e720dbb49>,0x29ab41effa61 <Node map = 0x2bb5fcc357c9>)
    4: vis...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Writing Node.js report to file: report.20200430.153057.26287.0.001.json
Node.js report completed
 1: 0xa02f90 node::Abort() [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
 2: 0xa033b5 node::OnFatalError(char const*, char const*) [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
 3: 0xb76ffe v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
 4: 0xb77379 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
 5: 0xd23ad5  [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
 6: 0xd24166 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
 7: 0xd309e5 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
 8: 0xd31895 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
 9: 0xd3434c v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
10: 0xcfaf1b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
11: 0x103d85e v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
12: 0x13c03d9  [/usr/local/lib/nodejs/node-v12.16.2-linux-x64/bin/node]
Aborted
error Command failed with exit code 134.
  1. Error logs when this plugin is removed from your Rollup configuration.

When I remove compiler logs are fine.

@tarsinzer
Copy link

tarsinzer commented May 2, 2020

I also have this in a project where there are a lot of SCSS imports, with a long tree dependency
when I turn off almost all SCSS imports it compiles fine.

I didn't come up with an idea of what is it...

@quentincaffeino
Copy link
Author

What closure compiler has to do with CSS imports?

@tarsinzer
Copy link

tarsinzer commented May 2, 2020

I can’t say that I am good at the closure compiler. In this regard, I am a complete beginner

but it seems to me that the problem is related to the circular dependency

usually, if I got similar errors, they were always related to the circular dependency and most likely my problem is precisely this

@kristoferbaxter
Copy link
Contributor

Apologies for delays looking into this. I’m out on paternity leave, but will try to address as soon as I can.

@quentincaffeino
Copy link
Author

No worries. Thanks for your time.

Also I tried some more: If I run compiler in dev environment it runs fine. Even in advanced mode. Then it has undefined regeneratorRuntime but that's probably an issue with my babel setup.

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

3 participants