【问题标题】:Increase node memory using npm package.json script使用 npm package.json 脚本增加节点内存
【发布时间】:2018-01-22 13:37:06
【问题描述】:

如果你想增加节点的内存限制,要传递的选项是:

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

感谢您的帮助。

【问题讨论】:

    标签: node.js reactjs npm electron electron-builder


    【解决方案1】:

    回答我自己:在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",
    

    这样就可以了!

    【讨论】:

      【解决方案2】:

      你不必在 package-win 中使用选项。 你应该使用的方式-

          "build-ts-prod": "node --max-old-space-size=1024 
          ./node_modules/typescript/bin/tsc --skipLibCheck --diagnostics",
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-26
        • 2018-09-04
        • 2016-12-05
        • 2016-06-03
        • 1970-01-01
        • 2021-10-03
        • 2020-05-16
        • 2021-10-01
        相关资源
        最近更新 更多