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.

vue-cli-plugin-electron-builder

See original GitHub issue

Hey there! I’m trying to use some Node.js modules in a Web Worker in an Electron app written in Vue. The problem is when I want to import or require those Node.js modules (including things like serialport and stuff) I get an error and I can’t use any of them. I’ve read it here and there and I know it is something known, but I can’t really figure out what’s going on cause I have very little experience with both Electron and Webpack. By the way, any help will be really appreciated!

Used Vue plugin Github page: https://github.com/nklayman/vue-cli-plugin-electron-builder Link to another issue trying to explain this: #75

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
haroldiedemacommented, Nov 5, 2020

@MehrdadKhnzd - Here is a very nasty hack to make it work in Electron (since the native require method is always available when nodeIntegrationInWorker is enabled):

        const r = global['req' + 'uire'];

        const fs   = r('fs'),
              path = r('path');

// You can now use fs.existsSync() inside the worker.
console.log(fs.existsSync('hello-world.txt'));

The whole point of this ‘hack’ is to trick Webpack into thinking you’re not actually using the require function, so it’ll stay away trying to ‘transpile’ your code… Its disguisting to use, but at least it works…for now.

0reactions
2xAAcommented, Mar 20, 2021

Thanks for the hack, @haroldiedema. This issue should be re-opened for sure, but the above does work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue CLI Plugin Electron Builder
Easily Build Your Vue.js App For Desktop With Electron.
Read more >
nklayman/vue-cli-plugin-electron-builder: Easily Build ... - GitHub
Open a terminal in the directory of your app created with Vue-CLI 3 or 4 (4 is recommended). Then, install and invoke the...
Read more >
vue-cli-plugin-electron-builder - npm
Easily Build Your Vue.js App For Desktop With Electron. Latest version: 2.1.1, last published: 2 years ago.
Read more >
Vue CLI Plugin Electron Builder
"VCP Electron Builder is a Vue CLI plugin for Electron with no required configuration. Write once, run everywhere – If it works as...
Read more >
vue-cli-plugin-electron-builder 1.0.0-beta.3 vulnerabilities - Snyk
Learn more about known vue-cli-plugin-electron-builder 1.0.0-beta.3 vulnerabilities and licenses detected.
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