在React应用程序中执行子进程

时间:2018-12-07 08:37:24

标签: javascript reactjs npm child-process

我想知道应该使用哪个模块从React应用程序执行子进程。

要求是: 我需要有一个按钮,单击该按钮应为应用程序运行npm test并生成将根据需要呈现的报告。 我遇到的困难是单击时执行该npm test命令...如果我手动执行该命令,其余部分将正常工作。

我尝试使用子进程和子进程承诺模块,但是它不起作用。

import { exec } from 'child-process-promise';


testCode = () => {
    exec("cd ../../ && npm test")
    .then((data) => console.log(data))
    .catch(err => console.log(err))
}

// it thorws an error in the import 
//TypeError: Cannot read property 'split' of undefined [in index.js of child-proceess-promise module]
error message image

0 个答案:

没有答案