sheerun / targets-webpack-plugin

Webpack plugin for transcompilig final bundles so they support legacy browsers
MIT License
15 stars 4 forks source link

JavaScript heap out of memory #4

Open Enalmada opened 5 years ago

Enalmada commented 5 years ago

I tried using v2.0.0 with my nextjs sample project and got a javascript error: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

--max_old_space_size=4096 seems to fix it. Just wanted to call it out incase it is worth noting in the readme or helps someone searching: cross-env NODE_OPTIONS=--max_old_space_size=4096 next build

Let me know if there is something that could be done to debug further if you think this might be due to something bad rollup is doing on the targets-webpack-plugin side.

Full stacktrace:

<--- JS stacktrace --->

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

    0: ExitFrame [pc: 0000024FB24DC5C1]
Security context: 0x0076e479e6e1 <JSObject>
    1: push [00000076E4785851](this=0x0266ed0f8a21 <JSArray[0]>,0x03a9ef7bab09 <Int16Array map = 00000130F1104671>)
    2: decode(aka decode) [000002A60C0F67A9] [<myproject>\node_modules\rollup\dist\rollup.js:~655] [pc=0000024FB3C4DB2E](this=0x023b7bd026f1 <undefined>,mappings=0x030d42836c81 <Very long string[187568]>)...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF73EB8ECE5
 2: 00007FF73EB68196
 3: 00007FF73EB68BA0
 4: 00007FF73EDF8D5E
 5: 00007FF73EDF8C8F
 6: 00007FF73F3369D4
 7: 00007FF73F32D137
 8: 00007FF73F32B6AC
 9: 00007FF73F334627
10: 00007FF73F3346A6
11: 00007FF73EED7767
12: 00007FF73EF6F44A
13: 0000024FB24DC5C1
sheerun commented 5 years ago

You need to disable this plugin in development environment, it should be used only on CI. Heap out of memory has nothing to do with this plugin, your system just doesn't have enough memory for build.

sheerun commented 5 years ago

You can also disable source maps, this should lower memory usage, just pass { sourceMaps: false }

Enalmada commented 5 years ago

I appreciate the sanity check. I was only getting error when building and am pretty sure I am using it as intended:

if (!dev) {
            config.plugins.push(new TargetsPlugin({
                browsers: ["last 2 versions", "chrome >= 41"]
            }))
        }

max_old_space_size seems to have something to do with it because it really seems to fix the error....if I remove it I get the error again and vice versa....but perhaps it is random...I will get more data. I have a 16g build machine and think I have plenty of free ram otherwise. I am testing it out on a sample project which I can make available if you are curious.

sheerun commented 5 years ago

Referring #3 where @sprguillen solved it by using webpack-bundle-analyzer and restructuting how plugins are being loaded by webpack.

sheerun commented 5 years ago

And tbh. I don't like that this plugin uses both babel and rollup to achieve its goal but I cannot find a way for babel-env to output browser-compatible builtins. Instead it outputs es6 which I need to transcompile for browser again..

sheerun commented 5 years ago

Or maybe I'll put it another way: there is no way for babel-env to directly output builtins instead of just putting requires in source, like import "core-js/modules/es7.array.includes" or define(["core-js/modules/es7.array.includes"],function(includes, ...){})

Enalmada commented 5 years ago

I am getting this on a sample project that is loading some plugins but not sure how to restructure how they are being loaded.

It might just be the way windows node manages heap. Seems like most of the reports I can see while searching about this error seem to be windows. I assume since I am getting this error during build that sourceMaps: false is not needed (I am assuming that is a dev only thing)? Thanks for confirming that "heap out of memory" has nothing to do with this plugin. I think the bottom line is that if anyone else has this issue...they are probably on windows...and then the solution is this: cross-env NODE_OPTIONS=--max_old_space_size=4096 next build

sheerun commented 5 years ago

Maybe @sprguillen can help to fix this sample project

sprguillen commented 5 years ago

Can you post your webpack config if you have one @Enalmada? Please

Enalmada commented 5 years ago

Here is the config for the sample project I am building as a test environment for everything I need in a production setup: https://github.com/Enalmada/next-reason-boilerplate/blob/master/next.config.js#L73-L85

If you have any ideas of things that could be better I would very much appreciate your feedback!

sheerun commented 1 year ago

Thank you @Enalmada