Skip to content

JavaScript heap out of memory (ts-node@1.4.1) #215

@TanaseHagi

Description

@TanaseHagi

Consider the following configuration:

> node --version
v6.7.0

> npm init
> npm i typescript@1.8.10 ts-node@1.3.0 mocha@3.1.0 chai@3.5.0 sinon@1.17.6 nock@8.0.0 redux-mock-store@1.2.1 redux-thunk@2.1.0 redux@3.6.0
> 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);
    });
});

ts-node@1.3.0

> 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)

ts-node@1.4.1

> npm i ts-node@1.4.1

> 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 ts-node@1.4.1 crashes while ts-node@1.3.0 compiles.
I am fully aware that the spec fails. The issue is with the ts compilation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions