"API fatal error handler returned after process out of memory on the background thread" 在构建 angular 电子应用程序时

"API fatal error handler returned after process out of memory on the background thread" when building an angular, electron app

我们正在使用 angular 10.2、electron 4.2、electron-builder 22.9 和节点 10.16.0。 此外,每次发出 Pull 请求时,我们都会执行一个 jenkins 管道。 此管道创建一个 AWS windows 实例 (t2.large) 以下载代码 并构建一个 .exe 文件。 问题是编译代码时,弹出此错误: Fatal error # API fatal error handler returned after process out of memory on the background thread.

节点变量--max_old_space_size value is 4191.868721008301 MB。 如果手动启动 AWS windows 实例,运行 npm install 并手动构建代码, 没有错误被触发并且构建完全成功。该错误仅在以下情况发生 jenkins 启动 AWS windows 实例。

--max_old_space_size=1.5GB 的 mac 环境中,构建过程完全成功。 同样,当在 windows 和 --max_old_space_size=1.5GB 中手动测试时,构建也很好。 如果变量设置为 --max_old_space_size=512MB 构建失败并出现不同的错误 Javascript 堆内存不足。

我猜是不是与 jenkins 线程内存有关?但我还没有找到如何增加 线程内存。

任何想法,提示都会有所帮助。

詹金斯文件:

stage ('Build Windows app') {
    node('windows-electron') {
        // Wipe the workspace so we are building completely clean
        deleteDir()

        checkout scm

        bat """
        cd app
        call npm run node-memory
        call node -v
        call npm --no-git-tag-version version \"${version}\"
        call npm install
        REM call npm run test - tests disabled on Windows for now (they run on Mac OS)
        call npm run build"""
    }
}

Package.json 构建脚本: "build": "npm run download-translations && ng build --prod && electron-webpack && electron-builder --publish=never",

由于这个问题从 angular 9 and 10 as well 开始,我们创建了一个 linux slave 来执行构建过程,然后在 mac 和 windows slaves 中存储文件和取消存储.

node('nvm-slave') {
        // Wipe the workspace so we are building completely clean
        deleteDir()

        checkout scm

        nvm(nvmInstallURL: 'https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh', nvmIoJsOrgMirror: 'https://iojs.org/dist', nvmNodeJsOrgMirror: 'https://nodejs.org/dist', version: '10.16.0') {
            sh '''cd app
            npm install
            npx ng build --prod
            '''
        }

        stash name: "folder-to-stash", includes: "path/to/folder/to/stash/**"
}

stage ('Build Windows app') {
    node('windows-electron') {
        // Wipe the workspace so we are building completely clean
        deleteDir()

        checkout scm

        unstash "folder-to-stash"

        bat """
        cd app
        call node -v
        call npm --no-git-tag-version version \"${version}\"
        call npm install
        REM call npm run test - tests disabled on Windows for now (they run on Mac OS)
        call npm run postbuild"""

        archiveArtifacts 'app/dist/*.exe'
    }
}

Package.json 脚本:

"build": "ng build --prod",
"postbuild": "electron-webpack && electron-builder --x64 --publish=never",