firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

4.13.0 & 4.13.1 JavaScript heap out of memory on prod build

Open ben-kn-app opened this issue 8 years ago • 43 comments

[REQUIRED] Describe your environment

  • Operating System version: Mac Os Sierra 10.13.3
  • Firebase SDK version: 4.13.1
  • Firebase Product: auth, realtime database, storage, functions, analytics

Using firebase within a ionic Android & Ios app. Ionic details:

@ionic/cli-utils  : 1.19.1
ionic (Ionic CLI) : 3.19.1

global packages:

cordova (Cordova CLI) : 7.0.1 

local packages:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : ios 4.4.0
Ionic Framework    : ionic-angular 3.9.2

System:

ios-deploy : 1.9.2 
Node       : v6.11.3
npm        : 5.8.0 
OS         : macOS High Sierra
Xcode      : Xcode 9.2 Build version 9C40b 

[REQUIRED] Describe the problem

ionic serve & ionic build run fine, without any problems. ionic cordova build ios --prod Throws: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

Running app-scripts build: --prod --platform ios --target cordova
[09:52:32]  build prod started ... 
[09:52:32]  clean started ... 
[09:52:32]  clean finished in 4 ms 
[09:52:32]  copy started ... 
[09:52:32]  copy finished in 177 ms 
[09:52:32]  deeplinks started ... 
[09:52:33]  deeplinks finished in 307 ms 
[09:52:33]  ngc started ... 
[09:52:44]  ngc finished in 11.24 s 
[09:52:44]  preprocess started ... 
[09:52:44]  preprocess finished in less than 1 ms 
[09:52:44]  webpack started ... 
<--- Last few GCs --->

  286768 ms: Mark-sweep 4024.5 (4134.3) -> 4024.5 (4134.3) MB, 4466.6 / 0.0 ms [allocation failure] [GC in old space requested].
  291077 ms: Mark-sweep 4024.5 (4134.3) -> 4024.5 (4134.3) MB, 4308.7 / 0.0 ms [allocation failure] [GC in old space requested].
  295172 ms: Mark-sweep 4024.5 (4134.3) -> 4028.4 (4118.3) MB, 4094.4 / 0.0 ms [last resort gc].
  299375 ms: Mark-sweep 4028.4 (4118.3) -> 4032.5 (4118.3) MB, 4202.6 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

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

    2: arguments adaptor frame: 3->1
Security context: 0x13e2c34cf781 <JS Object>
    3: map [native array.js:~994] [pc=0x3e9139fa86c1] (this=0x1e42a850cbc1 <JS Array[1]>,bq=0x1a24728a54b1 <JS Function (SharedFunctionInfo 0x376baaf067d9)>,br=0x13e2c3404381 <undefined>)
    4: arguments adaptor frame: 1->2
    5: signatureToSignatureDeclarationHelper(aka signatureToSignatureDeclarationHelper) [/Users/ben/Documents/Projects/netwerkApp/netwe...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [

Steps to reproduce:

npm install -g ionic cordova
Ionic start helloWorld blank
cd helloWorld
ionic cordova platform add [email protected]
ionic cordova build android --prod (no error, goes well)
npm i [email protected]
Add to src/app/app.module.ts 
import firebase from 'firebase';

firebase.initializeApp({
    apiKey: "AIzaSyBNHCyZ-bpv-WA-HpXTmigJm2aq3z1kaH8",
    authDomain: "jscore-sandbox-141b5.firebaseapp.com",
    databaseURL: "https://jscore-sandbox-141b5.firebaseio.com",
    projectId: "jscore-sandbox-141b5",
    storageBucket: "jscore-sandbox-141b5.appspot.com",
    messagingSenderId: "280127633210"
});

ionic cordova build android --prod (gives  FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory)
npm i [email protected]
ionic cordova build android --prod  (works)

This only occurs (everything else being equal) after npm install [email protected] or npm install [email protected] npm instal [email protected] resolves this problem (workaround). also node --max-old-space-size=8192 /usr/local/bin/ionic cordova build ios --prod gives the same error. Which makes me believe there is a memoryleak somewhere introduced in 4.13.0, I've reproduced it with a minimal code example using android (so even ppl without a mac can test).

If you require more information let me know, I am happy to assist.

ben-kn-app avatar Apr 21 '18 08:04 ben-kn-app

@chinib I have just run into this and I proved it is happening by reverting to a commit 36 hours ago that I built and deployed to production successfully.

I have literally. OH MY GOD painstakingly gone through all 996 of my dependencies (yes you read that right!!) and checked which have changed in the last 24 hours. 😵 Firebase is the only one.

How did I notice? I turned webpack on full blast and took note of when it just.... stopped. It just stops and memory goes through the roof. I have tried giving Node 12GB of memory and it even blasts through that.

Not sure what changed in 4.13.1 but thank you @chinib for finding this - will revert to 4.12.1 for now and remove the carat from my package.json!!

codinronan avatar Apr 22 '18 00:04 codinronan

We seems to have ran into the same issue. This is basically a show-stopper for our Ionic prod builds.

zarko-tg avatar Apr 23 '18 14:04 zarko-tg

I am facing the same issue since the Firebase 4.13.0, and the issue is still present in the 4.13.0 and 4.13.1.

The app-scripts build of Ionic, when running in Prod, is running forever at the "webpack" step. It is working juste fine with firebase <= 4.12.1

tgensol avatar Apr 24 '18 09:04 tgensol

Funny part is that I NEED this update, it has a fix for navigator.onLine that is causing my Rollbar logs to get filled with fake errors (over 3000 of them per day!!)

https://firebase.google.com/support/release-notes/js#4.13.0

Error occurs but login is still successful. I believe this version fixes this issue... hopefully the amazing team can get a new version out soon that can build :)

codinronan avatar Apr 24 '18 14:04 codinronan

Downgrading to [email protected] wasn't enough for me. Had to make sure I was using @firebase/[email protected] too. This was preventing me from making an AOT build.

m-thompson-code avatar Apr 25 '18 00:04 m-thompson-code

Confirming that downgrading to [email protected] worked for me. Feel free to look at this repo for an example of an affected app.

CKunhardt avatar May 04 '18 23:05 CKunhardt

This issue still persist on [email protected] / [email protected] - Does anyone has a workaround (except downgrading to [email protected])?

UPDATE: The information of @moomoomamoo was the right one! I removed @firebase/[email protected] (which is installed with [email protected]) and replaced it with @firebase/[email protected] from [email protected] and NO memory heap :)

I will check tomorrow what changed there.

paulstelzer avatar May 08 '18 19:05 paulstelzer

It works for me with firebase 4.12.1 Thank you very much!!!!

Fomare avatar May 17 '18 15:05 Fomare

@paulstelzer any luck finding something in @firebase/[email protected] ?

ben-kn-app avatar May 18 '18 10:05 ben-kn-app

@chinib I find out that I load the Firebase Database althought I not used it - so I removed loading it and so I not get the error anymore. But if you need the package and the heap out of memory error occurs, then you have to use the older version of firebase@database

paulstelzer avatar May 18 '18 10:05 paulstelzer

Same here, you can use firebase ^5.0, but you need ton install @firebase/[email protected]...

tgensol avatar May 18 '18 10:05 tgensol

Thanks @tgensol. Adding @firebase/[email protected] to @chinib's solution worked for me.

david-ae avatar May 18 '18 17:05 david-ae

Confirming that this is still an issue with 5.0.4.

SteveKennedy avatar May 26 '18 16:05 SteveKennedy

Same issue. I'm using firebase 5.0.4... I was trying build using node --max-old-space-size=8192 But still getting "JavaScript heap out of memory" 516689 ms: Mark-sweep 8071.4 (8196.0) -> 8079.0 (8196.0) MB, 6603.7 / 0.0 ms [last resort gc].

ramzed avatar Jun 04 '18 16:06 ramzed

Bit disappointing to see there's no real reaction to this case by Firebase folks. What gives?

zarko-tg avatar Jun 04 '18 19:06 zarko-tg

Just another comment, pointing out that some have been able to solve this using firebase 5.0.x, but you need ton install "@firebase/database": "0.2.1".

SteveKennedy avatar Jun 05 '18 00:06 SteveKennedy

Could be cool to understand what changed between @firebase/[email protected] and @firebase/[email protected] and is still here. (And causing this error)...

tgensol avatar Jun 07 '18 16:06 tgensol

@tgensol hint worked for me. "@firebase/database": "0.2.1" "firebase": "^5.0.4"

ionic cordova build android --prod --release

JNSantiago avatar Jun 12 '18 12:06 JNSantiago

Confirming that this is still an issue with 5.1.0.

I had to use the older "@firebase/database" to be able to run a prod build as well, it is working with this set of packages, even though it is not recommended to reference the standalone packages directly it seems to work so far.

    "@firebase/app": "^0.3.3",
    "@firebase/auth": "^0.7.0",
    "@firebase/database": "^0.2.1",
    "@firebase/functions": "^0.2.4",
    "@firebase/logger": "^0.1.1",
    "@firebase/storage": "^0.2.3",

jayordway avatar Jun 22 '18 09:06 jayordway

Still an issue with firebase 5.2.0... @mikelehen or anybody from firebase could look at it ? (or at least say something please :( ) ?

Thanks !

tgensol avatar Jul 02 '18 13:07 tgensol