How to set max-old-space-size so it is honoured in NativeScript's VS Code extension running on OS X?

Viewed 1843

I've tried:

  • Executing export NODE_OPTIONS="--max-old-space-size=4096" in VS Code's bash prompt
  • Executing export NODE_OPTIONS="--max-old-space-size=4096" in a system bash prompt
  • Adding it to my user's .bashrc file and rebooting
  • Installing and running increase-memory-limit against the project

Nothing seems to work; debugging using VS Code on Mac seems impossible if the project goes above a certain size. I always end up with Ineffective mark-compacts near heap limit Allocation failed. It works running from bash, but not running from VS Code.

Does anyone have any thoughts?

1 Answers

I found a way to get this working and I thought I'd record it here for the benefit of others.

I had to patch the plugin with a hack, which can certainly be made more graceful (which I will attempt to achieve and submit a PR).

In nativeScriptCli.ts, I modified the following methods to add the NODE_OPTIONS environment variable to each spawn of Node:

public executeSync(args: string[], cwd: string): string {
    args.unshift('--analyticsClient', 'VSCode');
    const command: string = `${this._path} ${args.join(' ')}`;
    let env = process.env;
    env["NODE_OPTIONS"] = "--max-old-space-size=4096";

    this._logger.log(`[NativeScriptCli] execute: ${command}`);

    return execSync(command, { encoding: 'utf8', cwd, shell: this._shellPath, env: env }).toString().trim();
}

public execute(args: string[], cwd: string): ChildProcess {
    args.unshift('--analyticsClient', 'VSCode');
    const command: string = `${this._path} ${args.join(' ')}`;
    this._logger.log(`[NativeScriptCli] execute: ${command}`);
    let env = process.env;
    env["NODE_OPTIONS"] = "--max-old-space-size=4096";
    const options = { cwd, shell: this._shellPath, env: env };
    const child: ChildProcess = spawn(this._path, args, options);

    child.stdout.setEncoding('utf8');
    child.stderr.setEncoding('utf8');

    return child;
}

After installing this hacked version on my Mac, the app now successfully builds in VS Code.

Related