ampproject / ampproject/rollup-plugin-closure-compiler

JavaScript heap out of memory

Open
#372 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
293
Forks
28
PR merge metrics
No merged PRs in 30d

Description

## How do we reproduce the issue?

We'll likely need to know:
1. Your Rollup configuration.

```js
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
});
}
}
};
}
```

2. 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
3: enter [0x1d5b63285651] [/home/.../node_modules/@ampproject/rollup-plugin-closure-compiler/dist/index.js:1] [bytecode=0x878d4e4db89 offset=6](this=0x1d5b63285b51 ,0x29ab41effa61 )
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.
```

3. Error logs when this plugin is removed from your Rollup configuration.

When I remove compiler logs are fine.

Contributor guide

Open the contributing guide

Research direction

Start with the supplied Rollup configuration and the stack trace pointing to node_modules/@ampproject/rollup-plugin-closure-compiler/dist/index.js; compare the reported build with and without compiler(). Use the included Node.js heap logs and configuration to isolate the compiler-triggered failure. Done means the production build no longer exhausts the JavaScript heap when the plugin is enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.