Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugins aren't auto registered with bundled Capacitor Core #115

Open
hampoelz opened this issue Jul 17, 2021 · 1 comment
Open

Plugins aren't auto registered with bundled Capacitor Core #115

hampoelz opened this issue Jul 17, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@hampoelz
Copy link

hampoelz commented Jul 17, 2021

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.

@hampoelz hampoelz changed the title Plugins are not autoregistered with bundledWebRuntime Plugins aren't auto registered with bundled Capacitor Core Jul 17, 2021
@hampoelz
Copy link
Author

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.

@IT-MikeS IT-MikeS added the enhancement New feature or request label Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants