ENOENT Errors Once ElectronJS Project is Packaged

21 Views Asked by At

So I wrote a program using ElectronJS and packaged it via electron-packager. There's a line of code in there that utilizes fs.copyFileSync, which copies an image from the user to an internal folder in the project directory. To get the internal director path I of course use app.getPath() but have also used __dirname (neither work).

In a development environment, everything works and copies fine with no errors what so ever. However, once packaged, no matter what OS it's running on, whenever I try to copy an image from the user to the internal folder I get an ENOENT error.

I assume this is permission based or based on the fact that folder structure changes once packaged? Although I assumed app.getPath() would solve this it has not.

Any help would be much appreciated

EDIT: Here is the line of code doing the copying:

fs.copyFileSync(decodeURIComponent(Object.values(data)[1].substring(7)), path.join(__dirname, 'renderer', 'images', 'empPhotos', String(newEmpID).substring(1) + '.jpeg'), fs.constants.COPYFILE_EXCL, (err) => {
            if (err) throw err;
            e.returnValue = "FAIL";
        });

Here is the full error when ran in packaged format on MacOS (issue persists on all platforms):

Uncaught Exception:
Error: ENOTDIR: not a directory, copyfile '/Users/cjmagri/Documents/WBEMPPICS/addedvalue/Chasse Joe.png' -> '/Users/cjmagri/Documents/ElectronJS/prototype/Mathews Brothers WarBoard-darwin-x64/Mathews Brothers WarBoard.app/Contents/Resources/app.asar/renderer/images/empPhotos/221.jpeg'
at Object.copyFileSync (node:fs:2894:3)
at Object.func [as copyFileSync] (node:electron/js2c/asar_bundle:2:1822)
at IpcMainImpl.<anonymous> (/Users/cjmagri/Documents/ElectronJS/prototype/Mathews Brothers WarBoard-darwin-x64/Mathews Brothers WarBoard.app/Contents/Resources/app.asar/main.js:153:13)
at IpcMainImpl.emit (node:events:513:28)
at WebContents.<anonymous> (node:electron/js2c/browser_init:2:89638)
at WebContents.emit (node:events:513:28)
0

There are 0 best solutions below