Ts-node: JavaScript heap out of memory ([email protected])

Created on 10 Oct 2016  路  8Comments  路  Source: TypeStrong/ts-node

Consider the following configuration:

> node --version
v6.7.0

> npm init
> npm i [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
> typings install dt~mocha dt~chai dt~sinon dt~nock dt~redux-mock-store dt~redux-thunk --global

ts-node-bug.spec.ts

import * as chai from "chai";
let expect = chai.expect;
import * as sinon from "sinon";
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import * as nock from "nock";
const middlewares = [ thunk ];
const mockStore = configureMockStore(middlewares);

describe("authAction async", () => {
    afterEach(() => {
        nock.cleanAll();
    });

    it("gets token", () => {
        let req = {
            id: "676567456745764",
            password: "password",
            pf: true,
        };
        let res =  {
            data: {
                token: "token",
                user: {},
            },
        };
        nock("http://google.com")
            .post("/test/the/bug", req)
            .reply(200, res);
        const store = mockStore({
            auth: {
                loading: false,
                error: null,
                status: "tested",
            },
        });
        expect(false).to.equal(true);
    });
});

[email protected]

> node node_modules/mocha/bin/mocha --compilers ts:ts-node/register,tsx:ts-node/register --recursive --timeout 5000

authAction async                                       
  1) gets token                                       


0 passing (42ms)                                      
1 failing                                             

1) authAction async gets token:                       

  AssertionError: expected false to equal true      
  + expected - actual                               

  -false                                            
  +true                                             

  at Context.<anonymous> (ts-node-bug.spec.ts:37:26)

[email protected]

> npm i [email protected]

> node node_modules/mocha/bin/mocha --compilers ts:ts-node/register,tsx:ts-node/register --recursive --timeout 5000 ts-node-bug.spec.ts

<--- Last few GCs --->                                                                                                                            

57104 ms: Mark-sweep 1389.8 (1437.0) -> 1389.8 (1437.0) MB, 1149.6 / 0.0 ms [allocation failure] [scavenge might not succeed].                 
58132 ms: Mark-sweep 1389.8 (1437.0) -> 1389.8 (1437.0) MB, 1027.6 / 0.0 ms [allocation failure] [scavenge might not succeed].                 
59166 ms: Mark-sweep 1389.8 (1437.0) -> 1389.8 (1437.0) MB, 1033.8 / 0.0 ms [allocation failure] [scavenge might not succeed].                 


<--- JS stacktrace --->                                                                                                                           
Cannot get stack trace in GC.                                                                                                                     
FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory                         

> node node_modules/mocha/bin/mocha --compilers ts:ts-node/register,tsx:ts-node/register --recursive --timeout 5000 ts-node-bug.spec.ts

<--- Last few GCs --->                                                                                                                                                                                    

55560 ms: Mark-sweep 1388.6 (1438.0) -> 1388.6 (1438.0) MB, 1212.0 / 0.0 ms [allocation failure] [GC in old space requested].                                                                          
56738 ms: Mark-sweep 1388.6 (1438.0) -> 1388.6 (1438.0) MB, 1177.2 / 0.0 ms [allocation failure] [GC in old space requested].                                                                          
58010 ms: Mark-sweep 1388.6 (1438.0) -> 1391.0 (1422.0) MB, 1271.7 / 0.0 ms [last resort gc].                                                                                                          
59203 ms: Mark-sweep 1391.0 (1422.0) -> 1393.4 (1422.0) MB, 1193.5 / 0.0 ms [last resort gc].                                                                                                          


<--- JS stacktrace --->                                                                                                                                                                                   

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

Security context: 00000167B57CFB61 <JS Object>                                                                                                                                                            
    2: writeType [c:\Users\OK1\Desktop\ts-node bug\node_modules\typescript\lib\typescript.js:~16360] [pc=000003E00029C89D] (this=00000167B57E6601 <JS Global Object>,type=000003BBB05BC9F1 <a TypeObject w
ith map 0000035A19617551>,flags=0)                                                                                                                                                                        
    3: writeLiteralType [c:\Users\OK1\Desktop\ts-node bug\node_modules\typescript\lib\typescript.js:~16548] [pc=000003DFFFAD7BA1] (this=00000167B57E6601 <JS G...                                         

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory                                                                                                                         

A you can see [email protected] crashes while [email protected] compiles.
I am fully aware that the spec fails. The issue is with the ts compilation.

bug external

All 8 comments

If you can provide a reproduction, I'd be happy to investigate for you. As it is, I'm not sure there's any differences between 1.3.0 and 1.4.0 that could cause this issue.

@blakeembrey How can I provide a reproduction? I've provided info/details that produce the error. What more can I do?

Seems like a TypeScript issue without being able to reproduce myself. Maybe you were hitting an infinite loop somewhere in the compiler?

How Do I solve following error?
<--- Last few GCs --->>

91873 ms: Mark-sweep 1391.5 (1437.1) -> 1391.5 (1437.1) MB, 1263.2 / 0.0 ms [allocation failure] [scavenge might not succeed].
93098 ms: Mark-sweep 1391.5 (1437.1) -> 1391.5 (1437.1) MB, 1224.4 / 0.0 ms [allocation failure] [scavenge might not succeed].
94300 ms: Mark-sweep 1391.5 (1437.1) -> 1391.5 (1437.1) MB, 1202.0 / 0.0 ms [allocation failure] [scavenge might not succeed].
2: /* anonymous /(aka / anonymous */) [C:\Users\nbiradar\AppData\Roaming\npmnode_modules\protractornode_modules\selenium-webdriver\lib\webdriver.js:188] [pc=000003FA2F0C603B] (this=00000368019
04381 ,value=000000D6ADD95629 ,key=0000024A87472C31 )
<--- JS stacktrace --->orEachKey) [C:\Users\nbiradar\AppData\Roaming\np...
Cannot get stack trace in GC.
FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory

We basically need the ability to set the --max-old-space-size CLI argument like we can pass to the node executable. Can that be added?

Would like to be able to run ts-node as:

ts-node --max-old-space-size=4096 myApp.ts

See the README on how to use flags please.

The only thing I see is:

Note: If you need to use advanced node.js CLI arguments (e.g. --inspect), use them with node -r ts-node/register instead of the ts-node CLI.

Which I have done as a workaround but it would be nice to be able to pass through all node CLI arguments as a convenience. Is this not possible?

No, it鈥檚 not.

Was this page helpful?
0 / 5 - 0 ratings