How to use an unpackaged node module in Electron packaged build (trash npm)

62 Views Asked by At

I have an Electron app, and I'm using the trash npm module. In my code, the only way that I can import the package is like so:

let trash;
import('trash').then((trashModule) => { trash = trashModule.default || trashModule; });

And later in my script, I raise the trash function like so trash([imagePath]); This works fine when testing my Electron app via npm run start. But things are different in a packaged build.

So in my /dist/win-unpacked/ folder, I run the exe and trash is recognized and works properly. However, if I install the application via the setup exe in /dist/, it fails to find trash. It can only find the trash module if I run the exe in repo_path/dist/win-unpacked/.

The one difference about the trash module compared to all the other modules I use is that it does not pack into the asar file. It lives, unpacked, under a folder called app.asar.unpacked right next to the asar file.

TL;DR I want trash to work in packaged builds. Thoughts? Help?

I tried disabling asar in package.json, and I was able to get trash to work in packaged builds. However, I want to build with asar enabled.

0

There are 0 best solutions below