notpushkin / Mailspring-Libre

(archived) Mailspring Libre build – aiming at removing Mailspring's dependecy on a central server
GNU General Public License v3.0
335 stars 14 forks source link

How to import a module in plugin ? #20

Closed lefred closed 4 years ago

lefred commented 4 years ago

This is not really a bug or an issue, but looking for help as I'm new in JS world.

I'm trying to write a plugin that needs to use a module (dbus).

So in the code I've:

var DBus = require("dbus");

and of course, I added it in pakage.json too:

"devDependencies": {
  "@types/react": "^16.7.22",
  "typescript": "^3.6.3",
  "dbus": "^1.0.0"
},

But when I load it, I've in Mailscript the following issue I cannot get rid of:

/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:21 Uncaught Error: Module did not self-register.
    at process.module.(/usr/share/mailspring/resources/app.asar/static/anonymous function) [as dlopen] (ELECTRON_ASAR.js:160:31)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:722)
    at Object.module.(/usr/share/mailspring/resources/app.asar/static/anonymous function) [as .node] (ELECTRON_ASAR.js:160:31)
    at Module.load (internal/modules/cjs/loader.js:602)
    at tryModuleLoad (internal/modules/cjs/loader.js:541)
    at Function.Module._load (internal/modules/cjs/loader.js:533)
    at Module.require (internal/modules/cjs/loader.js:640)
    at require (internal/modules/cjs/helpers.js:20)
    at Object.<anonymous> (/home/fred/node_modules/dbus/lib/dbus.js:3)
    at Object.<anonymous> (/home/fred/node_modules/dbus/lib/dbus.js:103)
    at Module._compile (internal/modules/cjs/loader.js:693)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:704)
    at Module.load (internal/modules/cjs/loader.js:602)
    at tryModuleLoad (internal/modules/cjs/loader.js:541)
    at Function.Module._load (internal/modules/cjs/loader.js:533)
    at Module.require (internal/modules/cjs/loader.js:640)
    at require (internal/modules/cjs/helpers.js:20)
    at _toGtg (/usr/share/mailspring/resources/app.asar/src/my-gtg.jsx:10)
    at Object.fa (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:14)
    at ma (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:15)
    at na (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:15)
    at za (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:17)
    at Da (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:18)
    at Fa (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:18)
    at Ba (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:18)
    at Ia (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:21)
    at be (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:84)
    at Ii (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:231)
    at bc (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:39)
    at ee (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:86)
    at Ki (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:232)
    at de (/usr/share/mailspring/resources/app.asar/node_modules/react-dom/cjs/react-dom.production.min.js:85)
module.(anonymous function) @ ELECTRON_ASAR.js:160
Module._extensions..node @ internal/modules/cjs/loader.js:722
module.(anonymous function) @ ELECTRON_ASAR.js:160
Module.load @ internal/modules/cjs/loader.js:602
tryModuleLoad @ internal/modules/cjs/loader.js:541
Module._load @ internal/modules/cjs/loader.js:533
Module.require @ internal/modules/cjs/loader.js:640
require @ internal/modules/cjs/helpers.js:20
(anonymous) @ /home/fred/node_modules/dbus/lib/dbus.js:3
(anonymous) @ /home/fred/node_modules/dbus/lib/dbus.js:103
Module._compile @ internal/modules/cjs/loader.js:693
Module._extensions..js @ internal/modules/cjs/loader.js:704
Module.load @ internal/modules/cjs/loader.js:602
tryModuleLoad @ internal/modules/cjs/loader.js:541
Module._load @ internal/modules/cjs/loader.js:533
Module.require @ internal/modules/cjs/loader.js:640
require @ internal/modules/cjs/helpers.js:20
_toGtg @ my-gtg.jsx:10

If somebody can help me, that would be cool !

Cheers,

notpushkin commented 4 years ago

Hey, I've just replied to your email :) Let's continue here though, if you don't mind.

Unfortunately, native modules (like dbus) don't seem to have great support in Mailspring. I'm not sure yet if it is possible at all to launch those but even if you did it (https://www.electronjs.org/docs/tutorial/using-native-node-modules), you'd have to rebuild it every time Mailspring upgrades Electron, which happens every and.

If you still wanna try it though, could you also share your code (e. g. create a repo on GitHub) and run Mailspring in development mode which produces better tracebacks? (Developer → Run with Debug Flags, note that the config dir would be ~/.config/Mailspring-dev instead of ~/.config/Mailspring)

lefred commented 4 years ago

Self promotion of my not-yet-working plugin : https://github.com/lefred/mailspring-libre-gtg ;-)

lefred commented 4 years ago

I followed your instruction and it works ;) Thanks

lefred commented 4 years ago

In case somebody knows better than me where to get some info, I've added a question: https://github.com/lefred/mailspring-libre-gtg/issues/2