capacitor-community/electron

Plugins aren't auto registered with bundled Capacitor Core

hampoelz opened this issue · 1 comments

Describe the bug
When I use Capacitor with bundledWebRuntime enabled, installed Plugins aren't automatically registered. Only after the plugin is required it gets registered. So you can't use Capacitor.Plugins.MyPlugin directly, as if you're using the Android or iOS platform. You've to use require("my-plugin") first.

To Reproduce

  1. Create a new basic app: npm init @capacitor/app
  2. Add the Electron platform: npm i @capacitor-community/electron and npx cap add @capacitor-community/electron
  3. Install the Dialog plugin: npm install @capacitor/dialog, npx cap sync and npx cap sync @capacitor-community/electron
  4. Run the Electron app: npx cap open @capacitor-community/electron
  5. Enter the following code into the console and you'll get an Uncaught TypeError error: Capacitor.Plugins.Dialog.alert({ title: 'Test', message: 'This is a test', });
  6. Enter require('@capacitor/dialog');, repeat the above code and now it works.

Expected behavior
You shouldn't have to extra require the plugin.

The same problem exists for plugins with electron support. CapacitorElectronPlugins.MyPlugin works fine, but Capacitor.Plugins.MyPlugin returns undefined. If the packed version of the plugin is installed (with npm pack and npm install ../path/to/my-plugin/my-plugin-0.1.0.tgz) and you require the plugin now, the web implementation will be loaded. If you install the unpacked plugin with npm install ../path/to/my-plugin, the Electron implementation will be loaded.