Skip to content
Advertisement

The “original” argument must be of type function. Received an instance of Object

I used to have this:

const util = require('util');
const exec = util.promisify(require('child_process').exec);

Then I refactored to this (or at least my attempt to here):

import * as exec from 'child_process';
const execPromise = util.promisify(exec);

Now I am getting the error TypeError: The "original" argument must be of type function. Received an instance of Object on the exec in util.promisify

Not sure how to quite get this working like it was but with this new import syntax for Typescript (specifically related to `@typescript-eslint/no-var-requires

Advertisement

Answer

You’re looking for

import { exec } from 'child_process';
const execPromise = util.promisify(exec);

The * as exec did import the whole child_process module into a module namespace object.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement