fromdeno / deno2node

Compile your Deno project to run on Node.js.
MIT License
115 stars 3 forks source link

OOM crash #43

Closed 500-internal-server-error closed 3 months ago

500-internal-server-error commented 3 months ago

I installed and ran from npm as instructed in the README:

username@localhost:~ $ npm i -ED deno2node
username@localhost:~ $ tree -I node_modules
.
├── package.json
├── package-lock.json
├── src
│   └── cli.ts
└── tsconfig.json

2 directories, 4 files
username@localhost:~ $ cat tsconfig.json
{
    "compilerOptions": {
        "lib": [ "esnext" ],
        "target": "esnext",
        "module": "nodenext",
        "moduleResolution": "nodenext",
        "esModuleInterop": true,
        "isolatedModules": true,

        "strict": true,
        "forceConsistentCasingInFileNames": true,

        "outDir": "build/",
        "sourceMap": true,

        "skipLibCheck": true
    },

    "include": [
        "src/**/*.ts"
    ]
}
username@localhost:~ $ npx deno2node
Loading tsconfig: 251.637ms
Basic transformations: 4.139s
Emitting: 1.175s

<--- Last few GCs --->

[18928:00000234B24D7000]    43832 ms: Scavenge (interleaved) 4053.1 (4131.2) -> 4053.1 (4132.2) MB, pooled: 0 MB, 12.51 / 0.00 ms  (average mu = 0.138, current mu = 0.089) allocation failure;
[18928:00000234B24D7000]    44207 ms: Scavenge (interleaved) 4054.1 (4132.2) -> 4054.1 (4155.2) MB, pooled: 0 MB, 374.72 / 0.00 ms  (average mu = 0.138, current mu = 0.089) allocation failure;

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

 1: 00007FF6736BDA2B node::SetCppgcReference+15611
 2: 00007FF67362AFE4 DSA_meth_get_flags+86548
 3: 00007FF67428E351 v8::Isolate::ReportExternalAllocationLimitReached+65
 4: 00007FF67427AF76 v8::Function::Experimental_IsNopFunction+2918
 5: 00007FF6740C4DA0 v8::internal::StrongRootAllocatorBase::StrongRootAllocatorBase+31760
 6: 00007FF6740C1DAD v8::internal::StrongRootAllocatorBase::StrongRootAllocatorBase+19485
 7: 00007FF6740D7613 v8::Isolate::GetHeapProfiler+7267
 8: 00007FF6740D7EAA v8::Isolate::GetHeapProfiler+9466
 9: 00007FF6740E8A57 v8::Isolate::GetHeapProfiler+77991
10: 00007FF673DA5AEB v8::internal::Version::GetString+435643
11: 00007FF61432D9D0

cli.ts was obtained from here.

Running on Windows 11 x64 with 32GB of RAM, in case it matters.

KnorpelSenf commented 3 months ago

You're trying to compile 670 kB of minified JS. What's the issue here?

trgwii commented 3 months ago

@500-internal-server-error try this:

NODE_OPTIONS='--max-old-space-size=16384' npx deno2node
500-internal-server-error commented 3 months ago

@KnorpelSenf I would rather not install an entire new JS runtime just because the authors of the JS script I'm trying to run wrote it for a different runtime.

@trgwii Thanks, that seems to run without OOM crashes now. But now it's crashing elsewhere in the dependencies.

username@localhost:~ $ NODE_OPTIONS='--max-old-space-size=16384' npx deno2node
Loading tsconfig: 326.632ms
Basic transformations: 4.138s
Emitting: 1.209s
C:\Users\User\temp\deno\node_modules\@ts-morph\common\dist\typescript.js:120094
        output += formatCodeSpan(diagnostic.file, diagnostic.start, diagnostic.length, "", getCategoryFormat(diagnostic.category), host);
                  ^

RangeError: Invalid string length
    at Object.formatDiagnosticsWithColorAndContext (C:\Users\User\temp\deno\node_modules\@ts-morph\common\dist\typescript.js:120094:19)
    at Project.formatDiagnosticsWithColorAndContext (C:\Users\User\temp\deno\node_modules\ts-morph\dist\ts-morph.js:20711:26)
    at file:///C:/Users/User/temp/deno/node_modules/deno2node/lib/cli.js:35:30

Node.js v22.1.0

I thought the "string length" may be related to Windows' MAX_PATH (I've had that problem in the past), but subst to a shorter path didn't help.

KnorpelSenf commented 3 months ago

@500-internal-server-error where from do you take the script? Which tool is it?

500-internal-server-error commented 3 months ago

@KnorpelSenf

cli.ts was obtained from here

trgwii commented 3 months ago

RangeError: Invalid string length means the output JS string is too long for your JS engine to be able to represent it. So I guess something is causing an infinite loop. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length

wojpawlik commented 3 months ago

Diagnostics are simply too long. Try transforming the source instead.

500-internal-server-error commented 3 months ago

@wojpawlik Ah, the source makes use of deno modules. So I guess I'd have to rewrite it by hand anyway. Unless resolving deno dependencies is something this tool handles?

wojpawlik commented 3 months ago

dnt is likely better tool for the job.

KnorpelSenf commented 3 months ago

@KnorpelSenf

cli.ts was obtained from here

That is just some build output. Where's the original source? Is there a repo?

KnorpelSenf commented 3 months ago

I found the CLI that created it at https://github.com/FabricMC/fabricmc.net but that doesn't reveal the input source

wojpawlik commented 3 months ago

You're too slow :) It'd be nice if deno2node could auto-detect deno.jsonc?'s "vendor": true... but I'm not enthusiastic about dealing with 2nd config file.

wojpawlik commented 3 months ago

...just to allow omitting one line in existing config file.