PatrickJS-starter icon indicating copy to clipboard operation
PatrickJS-starter copied to clipboard

JS Heap out of memory when running build:aot:prod

Open doorman02 opened this issue 9 years ago • 24 comments

Note: for support questions, please use one of these channels: Chat: AngularClass.slack or Twitter: @AngularClass

  • I'm submitting a ... [X ] bug report [ ] feature request [ ] question about the decisions made in the repository

  • Do you want to request a feature or report a bug? Reporting a bug

  • What is the current behavior? When I run npm run build:aot:prod

I get the following error: ==== JS stack trace ========================================= Security context: 00000133277CFB61 1: enter [C:\MyApp\node_modules\optimize-js\lib\index.js:~13] [pc=00000269B6CE8F25] (this=000002BBF4E471E1 <an Object with map 000000D02DAA96D1>,node=0000022D23C7E1B9 <a Node with map 000003DD7E69E889>,parent=0000023AC9B9F6D9 <a Node with map 000003DD7E694801>) 2: arguments adaptor frame: 4->2 3: visit(aka visit) [C:\MyApp\node_m...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).

  • What is the expected behavior? To build successfully

  • What is the motivation / use case for changing the behavior?

  • Please tell us about your environment:

  • Angular version: 2.4.6
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

doorman02 avatar Feb 08 '17 10:02 doorman02

I am having this issue too. Maybe it is a leakage somewhere.

On the other hand, is there any way to increase the maximum RAM? I observed it crashed at around 1.5GB.

pilgylis avatar Feb 08 '17 10:02 pilgylis

I don't think this is an issue with the starter. Can you open it in the optimize-js

shlomiassaf avatar Feb 08 '17 10:02 shlomiassaf

We also need more information on how to reproduce it.

If I just clone the repo it doesn't happen...

shlomiassaf avatar Feb 08 '17 10:02 shlomiassaf

This does not happen with the repo on its own. It will start to happen if we use it in a project, and the project grows to a certain degree. Note: npm run build:prod runs ok.

pilgylis avatar Feb 08 '17 10:02 pilgylis

Is there a way to increase the maximum RAM for npm before run build:aot:prod?

doorman02 avatar Feb 08 '17 10:02 doorman02

node --max_old_space_size=4096

joshwiens avatar Feb 08 '17 11:02 joshwiens

How do we run it with the npm command? node --max_old_space_size=4096 npm run build:aot:prod?

doorman02 avatar Feb 08 '17 11:02 doorman02

So I added this script to the package.json file "myscript": "npm run build:aot:prod && node --max_old_space_size=4096" and ran it like this npm run myscript

But without luck still getting the heap out of memory error.

@pilgylis did you find a solution to this?

doorman02 avatar Feb 08 '17 14:02 doorman02

Tried various ways without any luck :(

How about splitting the aot build into multiple steps, for example, the first step is to generate the compile folder, and the second is to merge it?

I noticed that when the out of memory occured, the compile folder had been created. Can someone helps to create a command to continue from that?

pilgylis avatar Feb 09 '17 05:02 pilgylis

Finally made it work!! check out: https://github.com/AngularClass/angular2-webpack-starter/pull/1491/files

Also I had to made the following changes in order to work on my machine:

"webpack-dev-server": "node --max_old_space_size=4096 node_modules/webpack-dev-server/bin/webpack-dev-server.js", "webpack": "node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js"

pilgylis avatar Feb 09 '17 06:02 pilgylis

Wow, @pilgylis thanks a bunch :)

doorman02 avatar Feb 09 '17 15:02 doorman02

Hi, anybody can help me to resolve this mistake when id run npm run:build:aot it's throw a mistake JavaScript heap out of memory but when i use this resolvent it's also throw a mistake like this ` ERROR in ./~/extract-text-webpack-plugin/index.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/extract-text-webpack-plugin' @ ./~/extract-text-webpack-plugin/index.js 5:9-22 @ ./config/webpack.prod.js @ multi main

ERROR in ./~/html-webpack-plugin/index.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/html-webpack-plugin' @ ./~/html-webpack-plugin/index.js 3:9-22 @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/extract-text-webpack-plugin/loader.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/extract-text-webpack-plugin' @ ./~/extract-text-webpack-plugin/loader.js 5:9-22 @ ./~/extract-text-webpack-plugin/index.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/uglify-js/tools/node.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/uglify-js/tools' @ ./~/uglify-js/tools/node.js 8:9-22 @ (webpack)/lib/optimize/UglifyJsPlugin.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/assets-webpack-plugin/lib/output/createOutputWriter.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/assets-webpack-plugin/lib/output' @ ./~/assets-webpack-plugin/lib/output/createOutputWriter.js 3:9-22 @ ./~/assets-webpack-plugin/index.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/copy-webpack-plugin/dist/preProcessPattern.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/copy-webpack-plugin/dist' @ ./~/copy-webpack-plugin/dist/preProcessPattern.js 26:41-54 @ ./~/copy-webpack-plugin/dist/index.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/awesome-typescript-loader/dist/cache.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/awesome-typescript-loader/dist' @ ./~/awesome-typescript-loader/dist/cache.js 2:9-22 @ ./~/awesome-typescript-loader/dist/index.js @ ./~/awesome-typescript-loader/dist/entry.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/awesome-typescript-loader/dist/helpers.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/awesome-typescript-loader/dist' @ ./~/awesome-typescript-loader/dist/helpers.js 2:9-22 @ ./~/awesome-typescript-loader/dist/index.js @ ./~/awesome-typescript-loader/dist/entry.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/awesome-typescript-loader/dist/instance.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/awesome-typescript-loader/dist' @ ./~/awesome-typescript-loader/dist/instance.js 2:9-22 @ ./~/awesome-typescript-loader/dist/index.js @ ./~/awesome-typescript-loader/dist/entry.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in (webpack)/lib/node/NodeOutputFileSystem.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/webpack/lib/node' @ (webpack)/lib/node/NodeOutputFileSystem.js 5:9-22 @ (webpack)/lib/node/NodeEnvironmentPlugin.js @ (webpack)/lib/webpack.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/copy-webpack-plugin/dist/writeFile.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/copy-webpack-plugin/dist' @ ./~/copy-webpack-plugin/dist/writeFile.js 24:41-54 @ ./~/copy-webpack-plugin/dist/processPattern.js @ ./~/copy-webpack-plugin/dist/index.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/ngc-webpack/src/main.js Module parse failed: /Users/kunlun/Desktop/huala-system/node_modules/ngc-webpack/src/main.js Unexpected character '#' (1:0) You may need an appropriate loader to handle this file type. | #!/usr/bin/env node | "use strict"; | require('ts-node/register'); @ ./~/ngc-webpack/src/plugin.js 4:13-30 @ ./~/ngc-webpack/index.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in (webpack)/lib/NormalModule.js Module not found: Error: Can't resolve 'module' in '/Users/kunlun/Desktop/huala-system/node_modules/webpack/lib' @ (webpack)/lib/NormalModule.js 96:16-33 @ (webpack)/lib/NormalModuleFactory.js @ (webpack)/lib/Compiler.js @ (webpack)/lib/webpack.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/mkdirp/index.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/mkdirp' @ ./~/mkdirp/index.js 2:9-22 @ ./~/assets-webpack-plugin/lib/output/createOutputWriter.js @ ./~/assets-webpack-plugin/index.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in ./~/glob/glob.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/glob' @ ./~/glob/glob.js 43:9-22 @ ./~/copy-webpack-plugin/dist/processPattern.js @ ./~/copy-webpack-plugin/dist/index.js @ ./config/webpack.common.js @ ./config/webpack.prod.js @ multi main

ERROR in (webpack)/lib/node/NodeMainTemplateAsync.runtime.js Module not found: Error: Can't resolve 'fs' in '/Users/kunlun/Desktop/huala-system/node_modules/webpack/lib/node' @ (webpack)/lib/node/NodeMainTemplateAsync.runtime.js 9:2-15 25:3-16 @ (webpack)/lib/node/NodeMainTemplatePlugin.js @ (webpack)/lib/node/NodeTemplatePlugin.js @ (webpack)/lib/WebpackOptionsApply.js @ (webpack)/lib/webpack.js @ ./config/webpack.common.js @ ./config/webpack.prod.js `

Jarvens avatar Feb 16 '17 11:02 Jarvens

I am experiencing the same issue. It works fine with AOT until the code base gets larger, then you will start experiencing memory problems. The proposed fix, https://github.com/AngularClass/angular2-webpack-starter/pull/1491/files, works for me as well, but please include this or something better out-of-the-box, since everyone will start experience this sooner or later.

WillooWisp avatar Feb 20 '17 19:02 WillooWisp

Yes,When the programe become more and more large, AOT compress will encounter heap out of memory.When i use the above method to solve.There was another mistake.

Jarvens avatar Feb 21 '17 02:02 Jarvens

@pilgylis The change does not fix the AoT memory issue but it got built successfully since AoT configuration is ignored and it built as non-AoT

vincent-cm avatar Mar 01 '17 10:03 vincent-cm

What do you mean, not built as AoT? I only took this part from the proposed fix, "webpack": "node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js", that is increasing the memory and then node does not run of of memory anymore and the AoT build is successful.

WillooWisp avatar Mar 02 '17 06:03 WillooWisp

@WillooWisp I did not use this proposal, it will be very slow when doing AOT compression, but did not throw a memory overflow

Jarvens avatar Mar 02 '17 13:03 Jarvens

It sounds like there is no good solution yet. Why is this issue closed?

dereklin avatar Mar 19 '17 01:03 dereklin

The proposed solution seems to work. The trick is to make sure AOT mode is on. I have installed cross-env

npm install --save-dev cross-env

In package json, I have created a new script:

"aotwebpack": "node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js",

I leave the existing "webpack" script alone.

I changed "build:aot:prod" to:

"build:aot:prod": "npm run clean:dist && npm run clean:aot && cross-env BUILD_AOT=1 npm run aotwebpack -- --config config/webpack.prod.js  --progress --profile --bail",

And in webpack.common.js, just like the proposed solution:

const AOT = process.env.BUILD_AOT || helpers.hasNpmFlag('aot');

I am running angular 4.0.0-rc.5. I actually don't see much code reduction with aot -- I may have to change the way I import dependencies -- which I wish the tool can take care of this...

dereklin avatar Mar 19 '17 05:03 dereklin

I have the same problem. Please reopen the issue.

MehdiSaeedifar avatar Mar 20 '17 15:03 MehdiSaeedifar