問(wèn)題描述
我正在開(kāi)發(fā)一個(gè)通過(guò) gui 控制 gulp 任務(wù)的電子應(yīng)用程序.您單擊一個(gè)任務(wù),它就會(huì)運(yùn)行.很簡(jiǎn)單的東西.在 macOS 上,當(dāng)我運(yùn)行 npm start 時(shí),它運(yùn)行得很好,但是當(dāng)我用電子打包器打包它時(shí),我得到了這個(gè)錯(cuò)誤:
I'm working on an electron app that controls gulp tasks via gui. You click on a task and it runs. Pretty simple stuff. On macOS, when I run npm start it runs just fine, but when I package it with electron-packager, I get this error:
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'
});
}
});
};
推薦答案
如果其他人遇到這個(gè)問(wèn)題,答案是更正 $PATH.npm 上有一個(gè)包可以為你做這件事.
In case anyone else is running into this problem, the answer is to correct the $PATH. There is a package on npm that does this for you.
https://www.npmjs.com/package/fix-path
這篇關(guān)于電子包裝器產(chǎn)生 ENOENT的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!