Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass --max-old-space-size flag through to Node #261

Closed
danvk opened this issue Jan 3, 2017 · 16 comments
Closed

Pass --max-old-space-size flag through to Node #261

danvk opened this issue Jan 3, 2017 · 16 comments

Comments

@danvk
Copy link

danvk commented Jan 3, 2017

This controls the amount of memory that the node process is able to use.

@danvk
Copy link
Author

danvk commented Jan 4, 2017

Huh, it's --max-old-space-size (with hyphens) for the node command, but --max_old_space_size (with underscores) for ts-node.

@danvk danvk closed this as completed Jan 4, 2017
@juhoojala
Copy link

Is this information still accurate? Maybe this should be added to the documentation?

@blakeembrey
Copy link
Member

See https://github.com/TypeStrong/ts-node#programmatic.

@huan
Copy link

huan commented Jul 3, 2018

I'd like to put the answer right at here because this thread is on top of the google search ''ts-node max-old-space-size"

node -r ts-node/register --max-old-space-size=3049

Update

If you are running with os.arch() === 'ia32', the max value you can set is 3049

under my testing with node v11.15.0 and windows 10

  • if you set it to 3050, then it will overflow and equal to be set to 1.
  • if you set it to 4000, then it will equal to be set to 51 (4000 - 3049)

@aanno2
Copy link

aanno2 commented Nov 20, 2019

I'd like to put the answer right at here because this thread is on top of the google search ''ts-node max-old-space-size"

node -r ts-node/register --max-old-space-size

Ok, this makes it possibe to pass node options. However, with this solution I wonder how to pass ts-node options (like --project, -P).

@mrbar42
Copy link

mrbar42 commented Dec 26, 2019

since there is no obvious answer in this thread, here's how i ended up adding the flag:

node --max-old-space-size=4096 -- node_modules/.bin/ts-node -P tsconfig.json index.ts

@jpike88
Copy link

jpike88 commented Apr 7, 2020

why not just add a flag to ts-node and have it work as a passthrough?

@cspotcode
Copy link
Collaborator

ts-node does not actually invoke a node process. By the time ts-node is executing, it is already within a node process, and we don't want to invoke another one. So passing CLI flags to node is not something we can do. If we were to conditionally spawn a node process based on certain flags, this would add a bunch of complexity.

The recommended solution, mentioned here, is also explained in our README.
https://github.com/TypeStrong/ts-node#programmatic

Use node -r ts-node/register which allows passing any node arguments and specifying any ts-node options via environment variables and/or a "ts-node" sub-object in tsconfig.json.

@blakeembrey
Copy link
Member

Basically what @cspotcode said. We used to do this, then there were numerous requests for other flags to pass through. I believe it also created some obscure issues. Honestly just wasn't something we had bandwidth to maintain, and node's --require is already pretty great.

@KEMBL
Copy link

KEMBL commented May 6, 2020

node --max-old-space-size=4096 -- node_modules/.bin/ts-node -P tsconfig.json index.ts

guys, I had an error with that solution:

SyntaxError: missing ) after argument list

for me it works fine with that fix:

node --max-old-space-size=4096 -- node_modules/ts-node/dist/bin -P tsconfig.json index.ts

ts-node: 8.10.1

@beenotung
Copy link

@KEMBL in your case, node_modules/.bin/ts-node maybe a shell script

@beenotung
Copy link

node --max-old-space-size=4096 -- node_modules/ts-node/dist/bin.js -P tsconfig.json index.ts

It works for some case, but if you used advanced features, may get the error of Error: Cannot find module 'tslib'

@cspotcode
Copy link
Collaborator

cspotcode commented Jun 30, 2020 via email

@sgentile
Copy link

See https://github.com/TypeStrong/ts-node#programmatic.

I see you have posted this several times, however it's not clear where to put max_old_space_size

@sgentile
Copy link

ts-node does not actually invoke a node process. By the time ts-node is executing, it is already within a node process, and we don't want to invoke another one. So passing CLI flags to node is not something we can do. If we were to conditionally spawn a node process based on certain flags, this would add a bunch of complexity.

The recommended solution, mentioned here, is also explained in our README.
https://github.com/TypeStrong/ts-node#programmatic

Use node -r ts-node/register which allows passing any node arguments and specifying any ts-node options via environment variables and/or a "ts-node" sub-object in tsconfig.json.

do you have an example of this ?

I tried this but I get no output to confirm it when i run ts-node

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

@FireworksX
Copy link

If you use ESM for ts-node

node --loader ts-node/esm -r ts-node/register --max-old-space-size=8192 ./server/boot.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests