3.7.0: iOS build with --prod not working

Thx for the clarification :wink:

As fas as I saw, there are currently 3 open issues regarding the same subject in the app-scripts then on Github (I listed them above and I linked them all together in the GitHub issue tracker)

The size of the app. I’ve got maybe 30/40 pages and modals and other components.
Definitely not a small app but not a big one neither (depends on the point of view :wink:).

I don’t lazy load (yet, because of the duplication of the code of components used in many pages at build time)

Yes I saw the -max-old-space-size (see comment of @epetre in https://github.com/ionic-team/ionic-app-scripts/issues/1076)

I could confirm that this option, -max-old-space-size, is solving the problem too, I was able to build my app.

I just think that, right now, downgrading app-scripts, since it solves the problem too, is a more proper way to build my app if I want or need to release it

1 Like

If you only got this error since app-scripts 3.0.0 it is valid to open another one and include your ionic info and app information. This seems like an unrelated thing that only produces a similar error.

Sure, here you go:

Let me know if I need to add more informations

1 Like

We’ve been seeing this issue since @ionic/app-scripts@2.1.4. My own research tells me that the root cause of the issue is somewhere in Webpack 3. Since then, I’ve been using the following two workarounds to get our project to build:

  1. If you build by executing the npm scripts directly, such as npm run ionic:build --prod, then you can modify those scripts in package.json to something like the following:
    "ionic:build": "node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build"
  2. If you use the Ionic CLI’s commands to build, such as ionic build ios, then you should instead pass this setting to Node by setting the NODE_OPTIONS environment variable to --max_old_space_size=8192. This is due to the fact that the ionic command invokes node on your behalf, and there is no opportunity to pass the --max-old-space-size flag on the command line. This is the solution that we needed for our CI server.

I don’t know if you need to set a value as large as 8192. The builds don’t seem to take an appreciably different amount of time to complete, and it hasn’t blown up in our faces, yet. I personally run the npm scripts directly on my development machine, so I don’t have the environment variable set.

I’ve tested these workarounds on both v2.1.4 and v3.0.0 of @ionic/app-scripts, and our --prod builds are completing successfully on both.

3 Likes

No, exemplary issue :smiley:

1 Like

Hahaha you’re too kind :wink:

Awesome work, just a note: The CLI should also use ionic:build internally if I remember my tinkering correctly. Did you try setting it in scripts in package.json as well?

The CLI does use ionic:build. The problem is that you need to pass the --max-old-space-size flag to Node itself. Because the CLI invokes Node internally, the flag gets ignored, and the ionic command doesn’t know what to do with that flag, so you can’t pass it on the command line.

The only other way I’ve found to get the CLI to respect this setting is to manually patch the call to node in the CLI executables (such as node_modules/.bin/ionic). If there is anything that the Ionic team could actually “fix” here, it’s probably this, but it seems like the responsibility really belongs to the Webpack team.

1 Like

@danbucholtz pointed out a one cmd solution to the heap size problem in the issue I opened, respectively:

node --max-old-space-size=4096 /usr/local/bin/ionic cordova build ios --prod

I kind of like the fact that it’s only one cmd which still do ionic and cordova build and that I would not need a package.json modification

3 Likes

We’re working on coming up with a way to do this automatically in the background right now. We’re thinking if we cleverly fork a process we can supply the additional memory arg for you.

We’ll keep everyone posted.

Thanks,
Dan

4 Likes

This solution is beautiful and it worked perfectly on my build! Thank you @reedrichards and @danbucholtz !

1 Like

Glad to hear this is being looked at by the ionic team! As a dev with a few large projects, it’s always a little worrisome to be using various workarounds and wondering if updates will break them or affect their use.

Hi @reedrichards, I am building in Windows now and the memory limit is being a problem again. How can I run this command:

node --max-old-space-size=4096 /usr/local/bin/ionic cordova build ios --prod

In Windows. I do not know the location of “ionic” as /usr/local/bin/

Thanks in advance!

@rindegastos I’ve got so much no idea of the Windows environment, I’m really sorry
Hope someone else will be able to help you

I hope this solution helps everyone. To avoid executing the command with the --max-old-space-size=4096 I ended up changing the /bin/ionic or the ionic.cmd (windows) to the following:

#!/bin/node --max_old_space_size=4096

This way the --max-old-space-size=4096 is passed everytime and you can run all the commands normally.

1 Like

I have this configuration and add the --max-old-space-size=8084 on my .zshrc and this just adds time for the same error appear.

Ionic:

   ionic (Ionic CLI)  : 4.2.1 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.0.0, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 5 other plugins)

System:

   NodeJS : v10.10.0 (/usr/local/lib/node_modules/node/bin/node)
   npm    : 5.6.0
   OS     : macOS
   Xcode  : Xcode 10.1 Build version 10B61
<--- Last few GCs --->

[996:0x102801c00]   150213 ms: Mark-sweep 8037.4 (8187.9) -> 8037.4 (8189.4) MB, 9282.0 / 0.0 ms  (average mu = 0.076, current mu = 0.002) allocation failure scavenge might not succeed
[996:0x102801c00]   158621 ms: Mark-sweep 8038.4 (8189.4) -> 8038.4 (8190.4) MB, 8399.9 / 0.0 ms  (average mu = 0.038, current mu = 0.001) allocation failure scavenge might not succeed


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x16677fb5c01d]
    1: StubFrame [pc: 0x16677fb5d3df]
Security context: 0x28e47031e681 <JSObject>
    2: write [0x28e60aa4bdd9] [/Users/guifeliper/My Apps/TalkABit2019/node_modules/typescript/lib/typescript.js:~9597] [pc=0x1667809c9843](this=0x28e60aa4be81 <Object map = 0x28e42ebacf71>,s=0x28e44b5b6049 <String[2]: : >)
    3: write(aka write) [0x28e60aa4c769] [/Users/guifeliper/My Apps/TalkABit2019/node_modules/types...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x100039dbf node::Abort() [/usr/local/bin/node]
 2: 0x100039fc9 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x1001d1375 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x10059c572 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 5: 0x10059f045 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/bin/node]
 6: 0x10059aeef v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
 7: 0x1005990c4 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x1005a594c v8::internal::Heap::AllocateRawWithLigthRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
 9: 0x1005a59cf v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x100575354 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
11: 0x1007fcff4 v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x16677fb5c01d
13: 0x16677fb5d3df
[ERROR] Non-zero exit from subprocess.

I don’t know more what to do, anyone can help me?

1 Like

Any update…?? for the same reason build failed in Ionic Pro Package build!

I am using 12.18.1 and also increased the size to 16384 but still facing the same issue .

node --max-old-space-size=16384

I am using this command to build my project

sudo node --max-old-space-size=16384 /usr/local/bin/ionic cordova build android --release
sudo node --max-old-space-size=16384 /usr/local/bin/ionic cordova build ios --release

Please help