SAP / ui5-tooling

An open and modular toolchain to develop state of the art applications based on the UI5 framework
https://sap.github.io/ui5-tooling
Apache License 2.0
465 stars 69 forks source link

"JavaScript heap out of memory" error when declaring the ui5 tooling as a "dependency" #311

Closed IObert closed 1 year ago

IObert commented 5 years ago

Expected Behavior

The ui5 commands (e.g. ui5 serve) should work.

Current Behavior

Terminal "stalls" for some minutes and eventually fails with an error

Steps to reproduce the issue

  1. Clone the sample app
  2. Remove all devDependencies and turn them in normal dependencies
  3. Try to run ui5 serve -o index.html

Context

Affected components (if known)

Log Output / Stack Trace

 ui5 serve index.html

<--- Last few GCs --->

[3933:0x102801600]    73998 ms: Scavenge 1327.6 (1403.1) -> 1327.6 (1403.6) MB, 2.6 / 0.0 ms  (average mu = 0.322, current mu = 0.254) allocation failure 
[3933:0x102801600]    74002 ms: Scavenge 1327.9 (1403.6) -> 1327.9 (1404.6) MB, 2.5 / 0.0 ms  (average mu = 0.322, current mu = 0.254) allocation failure 
[3933:0x102801600]    74008 ms: Scavenge 1328.6 (1404.6) -> 1328.6 (1405.1) MB, 2.1 / 0.0 ms  (average mu = 0.322, current mu = 0.254) allocation failure 

<--- JS stacktrace --->

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

    0: ExitFrame [pc: 0x2b6bec7841bd]
Security context: 0x3ae69721e6c9 <JSObject>
    1: map [0x3ae697206ac9](this=0x3ae603ae44f1 <JSArray[3]>,0x3ae679489979 <JSFunction queue.push.project.dependencies.map (sfi = 0x3ae601164f51)>)
    2: dedupeTree [0x3ae6fd5027d9] [/Users/<user>/SoftwareDev/sandbox/openui5-sample-app/node_modules/@ui5/project/lib/translators/npm.js:~451] [pc=0x2b6bec9e960c](this=0x3ae6a13602d9 <NpmTranslator map = 0x3ae...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x100033d65 node::Abort() [/Users/<user>/.nvm/versions/node/v10.6.0/bin/node]
 2: 0x100035500 node::FatalTryCatch::~FatalTryCatch() [/Users/<user>/.nvm/versions/node/v10.6.0/bin/node]
 3: 0x10019f10a v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/<user>/.nvm/versions/node/v10.6.0/bin/node]
 4: 0x10056d6b2 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/<user>/.nvm/versions/node/v10.6.0/bin/node]
 5: 0x10056c669 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/Users/<user>/.nvm/versions/node/v10.6.0/bin/node]
 6: 0x10056a2f8 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/<user>/.nvm/versions/node/v10.6.0/bin/node]
 7: 0x10057683c v8::internal::Heap::AllocateRawWithRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/Users/<user>/.nvm/versions/node/v10.6.0/bin/node]
 8: 0x1005451d4 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/Users/<user>/.nvm/versions/node/v10.6.0/bin/node]
 9: 0x1007cf974 v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/<user>/.nvm/versions/node/v10.6.0/bin/node]
10: 0x2b6bec7841bd 
Abort trap: 6
RandomByte commented 3 years ago

I recall that Marius found a way to work around this. Anyways, to provide some information for anyone running into this kind of issue:

This is a known issue with projects that have many transitive npm dependencies. UI5 Tooling follows all dependencies of a project, and their dependencies. Due to shortcomings of that implementation "out of memory" errors like the one reported here can occur. We will hopefully improve this handling soon.

Until then you have two options depending on your project:

  1. Double check whether your dependencies could be devDependencies since those are ignored by default
  2. List those dependencies that are UI5 Tooling relevant in an additional "ui5.dependencies" array in your package.json:
    {
        "name": "my-app",
        "version": "1.0.0",
        "dependencies": {
            "some-non-ui5-dependency": "^1.0.0",
            "some-ui5-dependency": "^1.0.0"
        },
        "ui5": {
            "dependencies": [
                "some-ui5-dependency"
            ]
        }
    }

    Any direct dependencies which are not listed in that array will be ignored. This should resolve the reported issue with the dependency tree generation. This configuration is not documented and will become obsolete (ignored) once UI5 Tooling dependency handling has improved.

RandomByte commented 1 year ago

Surprised to see this issue is still open. This should be resolved with the v3 releases 🎉