使用child_process.execSync从nodejs运行更漂亮

时间:2020-01-10 19:58:47

标签: javascript node.js child-process

我正在尝试从Node.js应用程序中运行更漂亮的代码。代码如下:

const execSync = require('child_process').execSync;
console.log(execSync('prettier --help').toString());

运行应用程序时,输出如下:

child_process.js:669
    throw err;
    ^

Error: Command failed: prettier --help
    at checkExecSyncError (child_process.js:629:11)
    at execSync (child_process.js:666:13)
    at Object.<anonymous> (/home/borre/cubonacci/services/ui/temp.js:4:13)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)

我没有找到有用的方法来提取有关命令失败原因的更多信息。 stdoutstderr中都没有输出。

我能够以完全相同的方式运行其他应用程序。例如,将prettier替换为code将启动VS代码而不会出现问题。

如何从nodejs正确运行Prettier?

0 个答案:

没有答案