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
- Create a new basic app:
npm init @capacitor/app
- Add the Electron platform:
npm i @capacitor-community/electron
andnpx cap add @capacitor-community/electron
- Install the Dialog plugin:
npm install @capacitor/dialog
,npx cap sync
andnpx cap sync @capacitor-community/electron
- Run the Electron app:
npx cap open @capacitor-community/electron
- 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', });
- 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.