电子包装生成ENOENT

时间:2017-07-17 16:16:05

标签: javascript electron spawn enoent electron-packager

我正在开发一个通过gui控制gulp任务的电子应用程序。您单击任务并运行。非常简单的东西。在macOS上,当我运行npm start它运行得很好,但是当我用electron-packager包装它时,我收到这个错误:

Uncaught Exception:
Error: spawn gulp ENOENT
    at exports._errnoException (util.js:1022:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:359:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

这是代码:

exports.runTask = (taskName, projPath) => {
    const cp = spawn('gulp', [ taskName ], {cwd: projPath});
    cp.stdout.setEncoding('utf8');
    cp.stdout.on('data', data => {
        console.log(data);
        mainWindow.webContents.send('task-console-data', data);
    });

    cp.stderr.setEncoding('utf8');
    cp.stderr.on('data', data => {
        console.error(data);
        displayNotification({text: `[error] ${data}`});
        mainWindow.webContents.send('task-console-data', `[error] ${data}`);
    });

    cp.on('exit', code => {
        if (code === 0) {
          displayNotification({
            title: 'gulp',
            subtitle: 'Finished running tasks'
          });
        } else if ( !code || code === null ) {
            return;
        } else {
            console.error(`Exited with error code ${code}`);

            displayNotification({
                title: 'gulp',
                subtitle: `Exited with error code ${code}`,
                sound: 'Basso'
            });
        }
    });
};

1 个答案:

答案 0 :(得分:1)

如果其他人遇到此问题,答案是纠正$ PATH。 npm上有一个包为你做这个。

https://www.npmjs.com/package/fix-path