Ts-node: JS Heap out of memory

Created on 6 Apr 2018  Â·  11Comments  Â·  Source: TypeStrong/ts-node

When i'm using ts-node on a node project. When a child process reaches 1.5Gb in memory usage, the program begins to crawl and then crashes due to being out of memory.

I am passing the flag "start": "ts-node --max_old_space_size=8192 ./src/index.ts",
However the limit still applies.
Error Here:

<--- Last few GCs --->

[10280:000002B2CAF2C420] 279290 ms: Mark-sweep 1005.6 (1554.0) -> 1005.4 (1554.5) MB, 181.8 / 0.0 ms allocation failure GC in old space requested
[10280:000002B2CAF2C420] 279464 ms: Mark-sweep 1005.4 (1554.5) -> 1005.3 (1512.5) MB, 173.2 / 0.0 ms last resort GC in old space requested
[10280:000002B2CAF2C420] 279646 ms: Mark-sweep 1005.3 (1512.5) -> 1005.3 (1501.5) MB, 182.4 / 0.0 ms last resort GC in old space requested

<--- JS stacktrace --->

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

Security context: 00000147144254D9
1: _parseMappings(aka SourceMapConsumer_parseMappings) [C:\git\ProfessorX\node_modules\ts-node\node_modulessource-map\libsource-map-consumer.js:~468] [pc=000000F626AF5288](this=0000033C3DBB7739 ,aStr=0000033C3DBB6AB1 )
2: get [C:\git\ProfessorX\node...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::DecodeWrite
2: node_module_register
3: v8::internal::FatalProcessOutOfMemory
4: v8::internal::FatalProcessOutOfMemory
5: v8::internal::Factory::NewFixedArray
6: v8::internal::HashTable::IsKey
7: v8::internal::HashTable::IsKey
8: v8::internal::StringTable::LookupString
9: v8::internal::StringTable::LookupString
10: v8::internal::SourcePositionTableIterator::Advance
11: v8::internal::SourcePositionTableIterator::Advance
12: 000000F6269843C1

Dependencies

"dependencies": { "JSONStream": "^1.3.2", "node-progress-3": "^0.4.3", "typescript": "^2.7.2" }, "devDependencies": { "@types/chai": "^4.1.2", "@types/mocha": "^2.2.48", "@types/node": "^6.0.103", "chai": "^4.1.2", "codelyzer": "^4.2.1", "mocha": "^4.1.0", "ts-mockito": "^2.3.0", "ts-node": "4.1.0", "tslint": "^5.9.1", "typings": "^2.1.1" },
Thanks

wontfix

Most helpful comment

Unfortunately I'm going to close this as won't fix since passing node.js flags are no longer supported on master (see https://github.com/TypeStrong/ts-node/releases/tag/v5.0.0). You can use node --max_old_space_size=8192 -r ts-node/register ./src/index.ts on both versions though.

All 11 comments

Unfortunately I'm going to close this as won't fix since passing node.js flags are no longer supported on master (see https://github.com/TypeStrong/ts-node/releases/tag/v5.0.0). You can use node --max_old_space_size=8192 -r ts-node/register ./src/index.ts on both versions though.

Fantastic, fixes my issue!! Thanks!

Although. When I have child processes using the silent flag. They crash when they reach 250mb with no errors?

You could check the node.js issue tracker, crashes in this process are probably out of scope for me in ts-node and I wouldn't be sure where to start to help you, sorry.

How do I specify ts-node args with node --max_old_space_size=8192 -r ts-node/register ./src/index.ts? I need to provide it with --project...

And even without that I get Error: Cannot find module 'ts-node/register'? Whats the correct way to start ts-node with not-default --max_old_space_size?

How do I specify ts-node args with node --max_old_space_size=8192 -r ts-node/register ./src/index.ts? I need to provide it with --project...

And even without that I get Error: Cannot find module 'ts-node/register'? Whats the correct way to start ts-node with not-default --max_old_space_size?

I have the sam problem. I don't know how to pass --project parameter with node --max_old_space_size=8192 -r ts-node/register ./src/index.ts. Can anyone help?

@krzysztof-raciniewski use environment variables to configure ts-node - you want to set a value for TS_NODE_PROJECT (https://github.com/TypeStrong/ts-node#cli-and-programmatic-options)

@krzysztof-raciniewski use environment variables to configure ts-node - you want to set a value for TS_NODE_PROJECT (https://github.com/TypeStrong/ts-node#cli-and-programmatic-options)

I'm not sure I follow - ie. I'm using this

"ts-server": "NODE_PATH=/.src ts-node --max_old_space_size=8192 -r tsconfig-paths/register src/index.ts",

getting an ARG_UNKNOWN_OPTION error

@krzysztof-raciniewski use environment variables to configure ts-node - you want to set a value for TS_NODE_PROJECT (https://github.com/TypeStrong/ts-node#cli-and-programmatic-options)

like this?

"ts-node": {
        "maxOldSpaceSize": 8196
    },

it's not clear how to pass a value and the cli doesn't confirm it's applied

@krzysztof-raciniewski use environment variables to configure ts-node - you want to set a value for TS_NODE_PROJECT (https://github.com/TypeStrong/ts-node#cli-and-programmatic-options)

like this?

"ts-node": {
        "maxOldSpaceSize": 8196
    },

it's not clear how to pass a value and the cli doesn't confirm it's applied

No. It's done like the above in your first comment. Which option is giving you the error? Could you include the trace?

I need to set maxOldSpaceSize (topic of thread)

What is environmental variable for that - this is very unclear.

On Fri, Jan 29, 2021 at 9:27 AM James Read notifications@github.com wrote:

@krzysztof-raciniewski https://github.com/krzysztof-raciniewski use
environment variables to configure ts-node - you want to set a value for
TS_NODE_PROJECT (
https://github.com/TypeStrong/ts-node#cli-and-programmatic-options)

like this?

"ts-node": {
"maxOldSpaceSize": 8196
},

it's not clear how to pass a value and the cli doesn't confirm it's applied

No. It's done like the above in your first comment. Which option is giving
you the error? Could you include the trace?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/TypeStrong/ts-node/issues/566#issuecomment-769836388,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AABAKNANG4QVQGKHLVYPQODS4LAUFANCNFSM4EZKNQBQ
.

TS node does not support these as CLI arguments because it was difficult to maintain as a wrapper to node.js. The preferred way is using node.js directly (e.g. node --max_old_space_size=8192 --require ts-node/register) or via node.js provided CLI flags (e.g. NODE_OPTIONS='--max_old_space_size=8192'), both are documented in https://nodejs.org/api/cli.html#cli_command_line_options.

What @jameshmread is saying should work for you, you can use the node --max_old_space_size=8192 --require ts-node/register approach and set options for TS Node using environment variables (defined in https://github.com/TypeStrong/ts-node#cli-and-programmatic-options). For example, TS_NODE_PROJECT=... node -r ts-node/register. You can also set ts-node options in your tsconfig.json like above, but you can't use it to set node.js options.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nehalist picture nehalist  Â·  3Comments

max-block picture max-block  Â·  4Comments

mattdell picture mattdell  Â·  4Comments

cibergarri picture cibergarri  Â·  3Comments

dakom picture dakom  Â·  3Comments