question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

__dirname in electron&vue (webpack) context not working

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nerdv2commented, Oct 14, 2019

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.

0reactions
stale[bot]commented, Apr 14, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

__dirname is not defined · Issue #1234 · nklayman/vue-cli ...
Describe the bug I am attempting to use https://github.com/sindresorhus/electron-store for a simple key value store for app settings after installing I get ...
Read more >
vue.js - __dirname is not defined importing electron remote
I want to set up the minimize, maximize and close buttons on a frameless window but I can't due to this problem importing...
Read more >
node-loader - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
Quick Start | Electron
This guide will step you through the process of creating a barebones Hello World app in Electron, similar to electron/electron-quick-start.
Read more >
Getting Started with Electron, Typescript, React and Webpack
Start with a basic Electron project then configure it to use ... process does not need to know it's being used within an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found