PatrickJS / PatrickJS-starter

MFE Starter
MIT License
10.33k stars 4.89k forks source link

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

Closed doorman02 closed 7 years ago

doorman02 commented 7 years ago

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

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

pilgylis commented 7 years ago

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.

shlomiassaf commented 7 years ago

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

shlomiassaf commented 7 years ago

We also need more information on how to reproduce it.

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

pilgylis commented 7 years ago

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.

doorman02 commented 7 years ago

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

joshwiens commented 7 years ago

node --max_old_space_size=4096

doorman02 commented 7 years ago

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

doorman02 commented 7 years ago

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?

pilgylis commented 7 years ago

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 commented 7 years ago

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"

doorman02 commented 7 years ago

Wow, @pilgylis thanks a bunch :)

Jarvens commented 7 years ago

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 `

WillooWisp commented 7 years ago

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.

Jarvens commented 7 years ago

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.

vincent-cm commented 7 years ago

@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

WillooWisp commented 7 years ago

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.

Jarvens commented 7 years ago

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

dereklin commented 7 years ago

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

dereklin commented 7 years ago

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...

MehdiSaeedifar commented 7 years ago

I have the same problem. Please reopen the issue.

pilgylis commented 7 years ago

@dereklin AOT does not mean code reduction...

dereklin commented 7 years ago

@pilgylis AOT doesn't necessarily mean code reduction, but it should do tree shaking, which will generally mean code reduction. At the moment, tree shaking is broken in webpack 2.2. I'll wait for webpack 2.4 to see if tree shaking will work again without rewriting my import statements.

pilgylis commented 7 years ago

AOT converts the HTML templates into javascript so sometimes it even makes the code bigger. What you will benefit from it is that it saves you the time to do the compilation later.

dereklin commented 7 years ago

https://angular.io/docs/ts/latest/cookbook/aot-compiler.html#!#tree-shaking