__dirname in electron&vue (webpack) context not working
See original GitHub issueI am having a tough time to get pdf silent print working in our electron-vue app. The reason is, that pdf-to-printer is using __dirname in pdf-to-printer/src/win32/print.js, and in webpack context, this does not return the expected path as stated here: https://simulatedgreg.gitbooks.io/electron-vue/content/en/main-process.html#on-the-subject-of-using-dirname--filename
const getCommand = (pdf, options) => {
let command = path.join(__dirname, "SumatraPDF.exe");
command = fixPathForAsarUnpack(command);
command = `"${command}"`;
__dirname returns instead of the path to the module, just the path to the electron app root in dev mode (electron:serve) and to this in bundles app mode (electron:build)
In production I get this error: ‘“C:\Users\MYUSER\AppData\Local\Programs\my-electron-app\resources\app.asar.unpacked\SumatraPDF.exe”’ is not recognized as an internal or external command, operable program or batch file.
Possible solution I suggest, that you enable the user of your module to hand over the path to the Executable via another parameter or option.
Alternatives I’ve considered I tried to move SumatraPDF.exe with different attempts. The last one was to add an extraFIles section into the electronBuild configuration. But then, the SumatraPDF.exe ends up in the App root or resource folder, but not in resource/app.asar Because electron-vue abstracts so much away, it is not easy to add stuff to webpack or electronBuilder config. The configuration options are sometimes not so well documented, and because I’m working on a Mac, it takes ages in my Virtualbox Windows environment to build the app each time I change something.
Additional context I wonder, why this is working for others. You code suggests, that you have tested, because you event have fixPathForAsarUnpack in place.
Cheers, @matths
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top GitHub Comments
As a temporary fix, I just create the app.asar.unpacked folder inside resources folder and put the SumatraPDF after building the package using electron-builder.
And now printing works fine.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.