如何在 Typescript/Webpack 的 Bitbucket 管道中增加 NodeJS 堆(--max-old-space-size)? [英] How to increase NodeJS heap (--max-old-space-size) in Bitbucket Pipelines for Typescript/Webpack?

查看:61
本文介绍了如何在 Typescript/Webpack 的 Bitbucket 管道中增加 NodeJS 堆(--max-old-space-size)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在无服务器/TypeScript 项目的 webpack 打包步骤中遇到内存问题.

I am running into memory issues during the webpack packaging step in a serverless/TypeScript project.

我已经尝试过:

  • 'increase-memory-limit' npm 包无效
  • 从 npm 运行脚本调用以下命令

  • 'increase-memory-limit' npm package to no avail
  • Calling the following command from an npm run script

直接通过bitbucket-pipelines.yml调用以下命令.

Calling the following command directly through bitbucket-pipelines.yml.

node --max-old-space-size=4096 ./node_modules/.bin/serverless deploy

使用此命令在本地运行良好,但在 Bitbucket 管道中,我得到以下输出:

It works fine locally with this command, but in Bitbucket pipelines I get the following output:

    Serverless: Bundling with Webpack...

    internal/child_process.js:323
        throw errnoException(err, 'spawn');
        ^
    Error: spawn ENOMEM
        at _errnoException (util.js:1022:11)
        at ChildProcess.spawn (internal/child_process.js:323:11)
        at exports.spawn (child_process.js:502:9)
        at Object.exports.fork (child_process.js:103:10)
        at fork (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/fork.js:17:36)
        at Farm.startChild (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/farm.js:106:16)
        at Farm.processQueue (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/farm.js:279:10)
        at Farm.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/farm.js:97:21)
        at ontimeout (timers.js:475:11)
        at tryOnTimeout (timers.js:310:5)
        at Timer.listOnTimeout (timers.js:270:5)
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! platform-state-machine-import@0.0.2 deploy: `node --max-old-space-size=4096 ./node_modules/.bin/serverless deploy "--stage"    "feattsify" "--region" "us-east-1"`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the platform-state-machine-import@0.0.2 deploy script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /root/.npm/_logs/2019-02-07T22_37_25_150Z-debug.log

我在这里做了很多谷歌搜索和搜索,试图找出 Bitbucket 是否有某种环境.您可以为运行时参数等设置变量,但似乎找不到任何与上述 NPM 包无关的内容.

I've done a lot of googling and searching here to try to find if Bitbucket has some kind of env. variable you can set for runtime args, etc., but can't seem to find anything that doesn't tie back into the aforementioned NPM package.

推荐答案

我前段时间在一些 Jenkins 构建任务中遇到了类似的问题.您也许可以使用 NODE_OPTION 环境变量来解决它:

I encountered a similar issue some time ago in some Jenkins build tasks. You might be able to solve it using the NODE_OPTION environment variable:

NODE_OPTIONS=--max_old_space_size=4096

从您的错误堆栈跟踪来看,似乎正在生成新的节点进程.如果您可以设置此环境变量,则节点将使用它来将参数传递给任何新进程,以及此处内存不足的衍生进程.

From your error stacktrace, it looks like new node processes are beeing spawned. If you can set this environment variable, it will be used by node to pass arguments to any new processes, and so to the spawned processes that run out of memory here.

https://nodejs.org/dist/latest-v8.x/docs/api/cli.html#cli_node_options_options

这篇关于如何在 Typescript/Webpack 的 Bitbucket 管道中增加 NodeJS 堆(--max-old-space-size)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆