Skip to content

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

@benoitlahoz

Description

@benoitlahoz

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions