Readme should mention how to include the binaries
Venryx opened this issue · 3 comments
Title. I expected the library to automatically locate the binary files for the given platform, but instead it simply searches the working directory for the binaries. (requiring manual copying/distribution-alongside)
If you don't do so, you get this error (added for searches):
Error: spawn C:\...program path...\Dist\windows-trash.exe ENOENT
I ended up solving it by calling the below before using the library:
function EnsureTrashLibReady() {
const binaryFileName =
process.platform == "darwin" ? "macos-trash" :
process.platform == "win32" ? "windows-trash.exe" :
null;
if (binaryFileName) {
const binaryPath_src = paths.join(__dirname, "../node_modules/trash/lib", binaryFileName);
const binaryPath_dest = paths.join(__dirname, binaryFileName);
if (!fs.existsSync(binaryPath_dest)) {
fs.copyFileSync(binaryPath_src, binaryPath_dest);
}
}
}
Even if a specific solution like the above is not included, it would be nice at least for the readme to mention that this step is necessary, and maybe offering a suggestion on how to do so.
PS. This library is trash. (ie. helpful 🤣)
This is a problem with your system or how you use trash
. Trash is working fine for normal Node.js usage. Trash uses the correct absolute path to the binaries:
Line 11 in d6d2c3a
Oh I see what happened. I use webpack to bundle the code for my program, and it was bundling the trash
library's code into the same bundle, which was in the Dist
folder.
I was able to fix it (properly) by adding this to my webpack config:
webpackConfig.externals.trash = "commonjs trash";
Just coming here to mention that I had the same problem (where the trash
library's code was bundled with other packages and went to the wrong folder) and making a similar change in the webpack config file fixed my issue. Thanks to you both for your comments in this issue thread.