You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ionic构建Android时出现CALL_AND_RETRY_LAST内存分配失败错误求助

Hey there, I’ve dealt with this exact JavaScript heap out of memory error in Ionic Android builds plenty of times—let’s walk through the fixes that actually worked for me and other devs:

Fixes for "CALL_AND_RETRY_LAST Allocation failed" Error in Ionic Android Builds
  • Increase Node.js memory limit directly in your build command
    When running your build command, add the --max-old-space-size flag to allocate more memory to Node.js. You can adjust the value based on your system’s available RAM—8192 equals 8GB, which is a common starting point:

    node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build --prod
    

    If 8GB feels too heavy, try 4096 (4GB) first.

  • Add a custom npm script for easier builds
    Instead of typing the long command every time, update your package.json with a dedicated script:

    "scripts": {
      "build:android:prod": "node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build --prod"
    }
    

    Then just run npm run build:android:prod whenever you need to build for Android.

  • Clean up your project to eliminate corrupted files

    • Delete the node_modules folder, package-lock.json (or yarn.lock), and www folder
    • Run npm install to reinstall dependencies from scratch
    • Clear Ionic’s cache with ionic cache clear
      Corrupted dependencies or cached build files often make memory issues worse, so this fresh start can work wonders.
  • Trim down your project’s build size

    • Compress large images, fonts, or videos in your src/assets folder—unoptimized media bloats the build process
    • Use tools like webpack-bundle-analyzer to spot unused libraries or oversized code chunks that are being bundled unnecessarily
      Reducing the overall load on Node.js can prevent it from running out of memory.
  • Update your Ionic tooling and dependencies
    Outdated versions of Ionic, app-scripts, or Cordova sometimes have memory leaks or bugs that trigger this error. Run these commands to get the latest versions:

    npm install @ionic/app-scripts@latest --save-dev
    npm install ionic@latest -g
    cordova platform update android
    

If none of these steps resolve the issue, sharing your full ionic info output would help narrow things down further—but these fixes take care of 90% of the heap out-of-memory cases I’ve encountered.

内容的提问来源于stack exchange,提问作者Green Onyeji

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 07:03:33