javascriptnode.jstypescripttypescript1.7

Typescript returns execSync as undefined from the child_process module


I'm trying to use the function execSync from the module child_process.

But when I import the module:

/// <reference path="../../../../GENERAL/d.ts/node/node.d.ts" />
var execSync = require("child_process").execSync;

And try to use the function I get an exception saying that execSync is undefined.

I even tried to print the module to check the functions that are being imported and I got this result:

{ fork: [Function],
  _forkChild: [Function],
  exec: [Function],
  execFile: [Function],
  spawn: [Function] }

The d.ts file that's being used is the following one:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/node/node.d.ts


Solution

  • Given your node version is at 0.10.25 I think you need to upgrade node. The first line of the definition file says // Type definitions for Node.js v4.x

    To upgrade node run this command-

    sudo npm install -g n