小编zed*_*d45的帖子

Grunt任务中的节点JS - child_process spawn('npm install')导致ENOENT错误

我正在创作一个Grunt任务有些困难.我正在尝试执行npm install,然后执行bower install,然后执行grunt hub目标(触发多个子项目的构建命令).

我遇到的问题在于child_process.如果我在我的grunt任务中运行以下命令,并且当前已注释掉的npm install spawn命令,则会出现生成ENOENT错误:

    var path = require('path'),
        projectPath = path.resolve(process.cwd(), this.data.activity );

        grunt.log.debug('project path computed as: ', projectPath);
        process.chdir( projectPath );

        console.log('current dir is: ', process.cwd());
        console.log('EVN is: ', process.env);

        var spawnProcess = spawn('ls');
        // var spawnProcess = spawn('npm install');

        spawnProcess.stdout.on('data', function (data) {
            console.log('' + data);
        });

        spawnProcess.stderr.on('data', function(data) {

            console.log('something went wrong installing deps for ' + path + '.  Error: ', data);
        });

        spawnProcess.on('close', function (exitCode) {

            console.log( 'ls has finished with Exit …
Run Code Online (Sandbox Code Playgroud)

node.js npm gruntjs

8
推荐指数
1
解决办法
7580
查看次数

标签 统计

gruntjs ×1

node.js ×1

npm ×1