Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue.js + Electron + Typescript unable to import native modules #39

Open
benoitlahoz opened this issue Apr 7, 2021 · 1 comment
Open

Comments

@benoitlahoz
Copy link

Hello and thank you for the great work!

I'm building an app in Typescript with Electron (electron-builder) and Vue.js

The plugin seems to be ok, as it bundles my worker correctly.

Then, in the worker, I try to import 'is-online' module, that works great in the main thread but gives a Can't resolve 'dgram' in... in the worker (so... error happens when the module imports a submodule), and tried 'is-reachable' module giving this time Can't resolve 'dns'.

When importing directly the 'dns' module I have the same error.

Module build failed (from ./node_modules/threads-plugin/dist/loader.js):
ModuleNotFoundError: Module not found: Error: Can't resolve 'dns' in '/Users/benoitlahoz/Documents/oz/mmmap/src/core/connectivity'
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/webpack/lib/Compilation.js:925:10
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/webpack/lib/NormalModuleFactory.js:401:22
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/webpack/lib/NormalModuleFactory.js:130:21
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/webpack/lib/NormalModuleFactory.js:224:22
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/neo-async/async.js:2830:7
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/neo-async/async.js:6877:13
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/webpack/lib/NormalModuleFactory.js:214:25
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/enhanced-resolve/lib/Resolver.js:213:14
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/Users/benoitlahoz/Documents/oz/mmmap/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/Users/benoitlahoz/Documents/oz/mmmap/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/Users/benoitlahoz/Documents/oz/mmmap/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
    at /Users/benoitlahoz/Documents/oz/mmmap/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43

FYI, nodeIntegration is set to false in Electron, sandbox to true, contextIsolation to true. But, I thought that, as I'm running the worker from the main process, it wouldn't be an issue.

I've read about babel '@preset/env' configuration, but for the time being it doesn't change anything. Am I missing something?

Thank you!

@rathboma
Copy link

I'm having a similar issue and have made a sample project to replicate it using better-sqlite3:

https://github.com/rathboma/bettersqlite3-electron-vue

I believe I need to add better-sqlite3 to the webpack externals for the threads build. Is there a way to tell if it's doing that, or a way to force it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants