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

Ubuntu 20 EC2实例Ionic环境升级后生成Android/IOS平台文件夹报错求助

Alright, let's dig into your issue—you're hitting two frustrating errors after upgrading your Ionic/Angular/Cordova/Node stack on an EC2 instance, right? Let's break down why this is happening and walk through actionable fixes:

问题背景

Previously, you could successfully generate Android/iOS platform folders for build transfer using:

  • Ionic CLI 6.18.1, @ionic/angular 5.9.3
  • Cordova CLI 10.0.0, Node.js 14.18.1

After upgrading to:

  • Ionic CLI 6.18.1, @ionic/angular 6.0.8
  • Cordova CLI 11.0.0, Node.js 16.14.0

You're now facing two persistent errors on your EC2 instance:

  1. FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
  2. Error at new SubprocessError
Why This Is Happening

1. JavaScript Heap Out of Memory

  • Node.js 16 uses an updated V8 engine with different memory management logic compared to Node.js 14. Angular 6's production build (with aggressive tree-shaking, code compression, and AOT compilation) is more memory-intensive than Angular 5, which pushes your EC2 instance's memory limits over the edge.
  • The Cordova 11 upgrade likely introduced new dependencies or modified build workflows that add to the memory footprint during platform preparation.

2. SubprocessError

This is almost certainly a secondary issue triggered by the heap memory error. When the Angular/Ionic build process crashes from OOM, it causes the child subprocess (handled by Ionic's utils-subprocess) to exit unexpectedly, throwing this error. It could also stem from minor compatibility gaps between Cordova 11 and Node.js 16, or permission/resource constraints on your EC2 instance.

Your Existing Fix Attempt

You tried addressing the memory issue by setting NODE_OPTIONS=--max_old_space_size=8192 and adding a high-memory build script to package.json:

"scripts": { 
  "ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build --configuration=prod", 
}

And ran npm run ng-high-memory—but the problem persists.

Actionable Fixes to Try

For the Heap Memory Error

  1. Crank up the memory allocation
    Try increasing the max_old_space_size to 12GB (12288) to give the build process more headroom. Update your scripts to tie the build directly to Cordova platform preparation:

    "scripts": {
      "ionic-build-prod": "node --max_old_space_size=12288 ./node_modules/@ionic/cli/bin/ionic build --prod",
      "cordova-prepare-android": "npm run ionic-build-prod && ionic cordova prepare android",
      "cordova-prepare-ios": "npm run ionic-build-prod && ionic cordova prepare ios"
    }
    

    Run the relevant command for your platform, e.g., npm run cordova-prepare-android.

  2. Optimize Angular build settings
    Tweak your angular.json to reduce memory load during production builds:

    • Temporarily disable memory-heavy optimizers to test if they're the culprit (not recommended for production, but useful for debugging):
      "configurations": {
        "production": {
          "buildOptimizer": false,
          "aot": false,
          // Keep your other production configs
        }
      }
      
    • Enable build caching to reuse previous build artifacts and reduce redundant work:
      "cli": {
        "cache": {
          "enabled": true
        }
      }
      
  3. Upgrade your EC2 instance
    If you're using a low-memory instance (like t2.micro), upgrade to a larger instance type (e.g., t2.large or higher). This is a straightforward hardware-level fix for persistent memory constraints.

For the SubprocessError

  1. Reset your dependencies and platforms
    Corrupted dependencies or platform files often cause subprocess issues. Run these commands to clean up:

    rm -rf node_modules package-lock.json
    npm install
    ionic cordova platform remove android ios
    ionic cordova platform add android@latest ios@latest
    
  2. Switch to a more stable Node.js 16 LTS version
    Node.js 16.14.0 might have minor compatibility quirks with Cordova 11. Use nvm to switch to the latest 16.x LTS release:

    nvm install 16.20.2
    nvm use 16.20.2
    
  3. Verify EC2 permissions
    Ensure the ec2-user has full read/write access to critical build folders:

    sudo chown -R ec2-user:ec2-user ./platforms ./www
    
  • Ionic Angular 6 Upgrade Guide: Focus on build workflow changes and dependency updates
  • Cordova 10 → 11 Migration Docs: Review platform compatibility and build step adjustments
  • Node.js 14 → 16 Migration Guide: Learn about V8 engine memory management changes
  • Angular CLI Build Optimization Docs: Explore how to tweak build parameters to reduce memory usage

内容的提问来源于stack exchange,提问作者Suvel Rathneswar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 13:27:31