supertokens-auth-react icon indicating copy to clipboard operation
supertokens-auth-react copied to clipboard

Heap size error

Open aolszewska opened this issue 3 years ago • 7 comments

When I upgrade supertokens-auth-react lib to 0.18 version, I keep getting node error in my terminal:

Files successfully emitted, waiting for typecheck results...

<--- Last few GCs --->

[41793:0x1046a7000]    72092 ms: Mark-sweep (reduce) 2043.7 (2050.8) -> 2042.9 (2052.0) MB, 899.7 / 0.0 ms  (average mu = 0.088, current mu = 0.005) allocation failure scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x1012da6a5 node::Abort() (.cold.1) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
 2: 0x1000a6309 node::Abort() [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
 3: 0x1000a646f node::OnFatalError(char const*, char const*) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
 4: 0x1001e8f17 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
 5: 0x1001e8eb3 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
 6: 0x100395db5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
 7: 0x10039785a v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
 8: 0x100392f85 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
 9: 0x1003908b0 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
10: 0x10039ef9a v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
11: 0x10039f021 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
12: 0x10036d0f7 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
13: 0x1006ebf98 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]
14: 0x100a718d9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/Users/agnieszka/.nvm/versions/node/v14.16.1/bin/node]

The error does not show up when I only use features from session receip. When I try to import anything (not even use) from emailpassword receip, the error occures. For example: import { EmailPasswordAuth } from 'supertokens-auth-react/recipe/emailpassword'. Increasing node process memory allocation does not seem to be a solution. When using only features from session receip, the node process running the app takes about 600MB of ram. When adding the import from emailpassword receip the memory consumed increases to over 2GB. I use node v14.16.1. Did anyone have a similar issue?

aolszewska avatar Jan 20 '22 13:01 aolszewska

I'm trying to reproduce the issue but it seems to be working fine for me. Does the same happen if you try to run the example app? or do you have some repo I could check out? Also, what system are you running on?

porcellus avatar Jan 20 '22 14:01 porcellus

Thanks for the quick answer @porcellus! You may check this here. Make sure to checkout to branch TREAS-349. Go to www folder and run:

  • yarn install
  • yarn start It should work OK now. Once you uncomment the line // import { EmailPasswordAuth } from 'supertokens-auth-react/recipe/emailpassword' here, you should see the "JavaScript heap out of memory" error.

I'm using macOS Catalina 10.15.7

aolszewska avatar Jan 20 '22 14:01 aolszewska

Thanks for the repo link, I would've never reproduced this otherwise. :) I've narrowed your build failing to this commit: 77df5edef34d12ca6f452a89f78e3c800391192d Specifically, the problem is the line:

/// <reference types="@emotion/react/types/css-prop" />

This also aligns with the difference in memory consumption: if you import a UI component, this also gets included. Removing this reference from our build artifacts makes your build run even with the newest SDK (v0.18.1). Tomorrow I'll try to figure out why/how this is added and what we can do about this all.

A workaround could be to increase the max memory size of the node processes: it reaches above 2Gb, but it stays below 4 in my experience. By default, the typechecker process ignores the memory limit set in your package.json (See this issue). You could use craco or something similar to fix this, but it takes more steps than I'd like.

I just wanted to let you know about the progress on this issue; sorry about the inconvenience.

porcellus avatar Jan 20 '22 22:01 porcellus

Thanks for checking and for your input. Would it be possible for you to give me some hints on how to configure craco to increase the memory limit for the typechecker?

aolszewska avatar Jan 21 '22 14:01 aolszewska

So the trouble seems to come from the emotion package polluting the global namespace. This should be fixed when the next version of emotion/react is released. Until then, I see no short-term fix from our side. The good news is that this is also solvable in your project by removing the "@emotion/core/types". This worked for me.

rm -rf node_modules
echo @emotion/core/types >> .yarnclean
yarn

Please check here for more details (and the yarn v2 workaround): emotion-js/emotion#1257

porcellus avatar Jan 21 '22 14:01 porcellus

Thanks! This worked for me and I was able to build the app, thank you for your help!

aolszewska avatar Jan 21 '22 15:01 aolszewska

Happy to help :) I'll leave this issue open until we upgrade emotion.

porcellus avatar Jan 21 '22 15:01 porcellus

This has been solved in 0.30 since we've dropped the emotion dependency.

porcellus avatar Mar 22 '23 20:03 porcellus