nklayman / vue-cli-plugin-electron-builder

Easily Build Your Vue.js App For Desktop With Electron
https://nklayman.github.io/vue-cli-plugin-electron-builder/
MIT License
4.12k stars 278 forks source link

Error: Cannot find module 'bcrypto.node' #1289

Closed iNDicat0r closed 3 years ago

iNDicat0r commented 3 years ago

Describe the bug Imported the following in background.js

const Libp2p = require("libp2p");
const KadDHT = require("libp2p-kad-dht");
const Bootstrap = require("libp2p-bootstrap");
const TCP = require("libp2p-tcp");
const Mplex = require("libp2p-mplex");
const { NOISE } = require("libp2p-noise");
...
  const node = await Libp2p.create({
    modules: {
      transport: [TCP],
      streamMuxer: [Mplex],
      connEncryption: [NOISE],
      peerDiscovery: [Bootstrap],
      dht: KadDHT,
    },
    config: {
      dht: {
        // dht must be enabled
        enabled: true,
      },
      peerDiscovery: {
        bootstrap: {
          interval: 60e3,
          enabled: true,
          list: bootstrapers,
        },
      },
    },
  });

and when i run electron it outputs the following:

App threw an error during load
Error: Cannot find module 'bcrypto.node'
    at moduleError (webpack:///./node_modules/loady/lib/loady.js?:154:15)
    at resolve (webpack:///./node_modules/loady/lib/loady.js?:89:9)
    at load (webpack:///./node_modules/loady/lib/loady.js?:99:16)
    at eval (webpack:///./node_modules/bcrypto/lib/native/binding.js?:11:86)
    at Object../node_modules/bcrypto/lib/native/binding.js (/home/Desktop/hello-world/dist_electron/index.js:1874:1)
    at __webpack_require__ (/home/Desktop/hello-world/dist_electron/index.js:20:30)
    at eval (webpack:///./node_modules/bcrypto/lib/native/hkdf.js?:10:17)
    at Object../node_modules/bcrypto/lib/native/hkdf.js (/home/Desktop/hello-world/dist_electron/index.js:1898:1)
    at __webpack_require__ (/home/Desktop/hello-world/dist_electron/index.js:20:30)
    at eval (webpack:///./node_modules/bcrypto/lib/hkdf.js?:12:20)

I can confirm that bcrypto is there. Also, bcrypto is a dep of another package so its already installed and being build.

I tried everything from scratch without vuejs and this plugin, and it worked, so its something with webpack or the way bundling is done.

I also tried this, but didnt work:

electronBuilder: {
      externals: ['bcrypto']
    }

Expected behavior It should run and connect to a remote peer

Environment (please complete the following information): Ubuntu 16.04


  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^2.6.11",
    "vue-router": "^3.2.0",
    "vuex": "^3.4.0",
    "libp2p": "^0.30.10",
    "libp2p-bootstrap": "^0.12.2",
    "libp2p-kad-dht": "^0.21.0",
    "libp2p-mplex": "^0.10.2",
    "libp2p-noise": "^2.0.5",
    "libp2p-tcp": "^0.15.3"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.5.0",
    "@vue/cli-plugin-eslint": "^4.5.0",
    "@vue/cli-service": "^4.5.0",
    "@vue/eslint-config-prettier": "^6.0.0",
    "babel-eslint": "^10.1.0",
    "electron": "^11.2.1",
    "electron-devtools-installer": "^3.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-vue": "^6.2.2",
    "prettier": "^1.19.1",
    "vue-cli-plugin-electron-builder": "^2.0.0-rc.6",
    "vue-template-compiler": "^2.6.11"
  }
nklayman commented 3 years ago

You need to mark the parent dep as an external, in this case libp2p-noise:

module.exports = {
  pluginOptions: {
    electronBuilder: {
      externals: ['libp2p-noise']
    }
  }
}