gpt4 book ai didi

javascript - 尝试运行命令时处理 Yeoman 自定义生成器中的错误事件

转载 作者:行者123 更新时间:2023-12-03 07:14:18 27 4
gpt4 key购买 nike

在使用 yeoman 自定义生成器构建应用程序时,我正在尝试启动一个 git 存储库,这是我在 install 步骤中得到的:

  install: function () {
this.installDependencies();
this.spawnCommand('npm', ['i', '--save' , 'express', 'mongodb', 'mongoose', 'lodash', 'bluebird', 'async', 'morgan']);
this.spawnCommand('git' ['init']); // Here fails
this.spawnCommand('git', ['add', '.']);
this.spawnCommand('git', ['commit', '-am', '"yo scaffolded app"']);
}

然而,当我尝试运行它时,我得到:

events.js:85
throw er; // Unhandled 'error' event
^
TypeError: Bad argument
at TypeError (native)
at ChildProcess.spawn (child_process.js:1136:26)
at Object.exports.spawn (child_process.js:995:9)
at spawn (/storage/home/dev/generator-koala/node_modules/yeoman-generator/node_modules/cross-spawn/index.js:87:19)
at spawnCommand (/storage/home/dev/generator-koala/node_modules/yeoman-generator/lib/actions/spawn_command.js:17:10)
at module.exports.yeoman.generators.Base.extend.install (/storage/home/dev/generator-koala/generators/app/index.js:72:10)
at /storage/home/dev/generator-koala/node_modules/yeoman-generator/lib/base.js:421:16
at processImmediate [as _immediateCallback] (timers.js:367:17)

我确实安装了 git,我应该如何解决这个问题?

最佳答案

您没有使用回调,因此将 spawnCommand 更改为 spawnCommandSync

install: function () {
this.installDependencies();
this.spawnCommandSync('npm', ['i', '--save' , 'express', 'mongodb', 'mongoose', 'lodash', 'bluebird', 'async', 'morgan']);
this.spawnCommandSync('git' ['init']);
this.spawnCommandSync('git', ['add', '.']);
this.spawnCommandSync('git', ['commit', '-am', '"yo scaffolded app"']);
}

关于javascript - 尝试运行命令时处理 Yeoman 自定义生成器中的错误事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33507444/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com