2017-08-14 162 views
0

如果你想增加节点的内存限制,该选项传递将是:增加使用节点内存NPM的package.json脚本

node --max-old-space-size=4096 yourFile.js

但在我的情况下,我使用的纱线,我的package.json看起来是这样的:

{ 
    "name": "myapp", 
    "productName": "myapp", 
    "version": "1.0.0", 
    "main": "app/main.js", 
    ... 
    "scripts": { 
    "package-win": "npm run build && build --win --x64", 
    "package-mac": "npm run build && build --mac", 
    ... 
    }, 
    ... 

我在Windows机器上执行yarn package-win调用电子制造商与react.js内置电子我的应用程序。但我总是得到npm ERR! code ELIFECYCLE由于内存不足。在我的mac中也得到了FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory错误,但仍然在调用yarn package-mac时生成了包(如何?我不知道)。

我搜索了很多关于如何使用--max-old-space-size=4096选项,但我还没有找到任何可行的方法。

我试过"package-win": "node --max-old-space-size=4096 npm run build && build --win --x64",但是路径在定位npm时有问题。即使我使用哪个npm,仍然无法识别which

感谢您的帮助。

回答

0

回答我自己:使用package-win中的此选项是错误的。由于package-win执行构建任务,因此:

"build": "npm run build-main && npm run build-renderer", 
... 
"build-main": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.main.prod.js --progress --profile --colors", 
"build-renderer": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.prod.js --progress --profile --colors", 

这样它的工作原理!