Pass --max-old-space-size flag through to Node
This controls the amount of memory that the node process is able to use.
Huh, it's --max-old-space-size (with hyphens) for the node command, but --max_old_space_size (with underscores) for ts-node.
Is this information still accurate? Maybe this should be added to the documentation?
See https://github.com/TypeStrong/ts-node#programmatic.
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)
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).
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
why not just add a flag to ts-node and have it work as a passthrough?
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.
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.
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
@KEMBL in your case, node_modules/.bin/ts-node maybe a shell script
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'
Without seeing a reproduction, this sounds like a problem with your code, not ts-node.
On Tue, Jun 30, 2020, 6:55 AM Beeno Tung [email protected] wrote:
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'
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TypeStrong/ts-node/issues/261#issuecomment-651719565, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC35OGYU4FVHU4JUEVJZHTRZHACFANCNFSM4C3IASOA .
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
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/registerwhich allows passing anynodearguments and specifying anyts-nodeoptions 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
},
If you use ESM for ts-node
node --loader ts-node/esm -r ts-node/register --max-old-space-size=8192 ./server/boot.ts