Problem using 'Share' plugin

After adding the Share plugin as per the instructions:

I get the following error on starting the app:
export 'registerPlugin' (imported as 'registerPlugin') was not found in '@capacitor/core'

I only found this answer:

but I’m not sure how it relates to my setup.

My src-android/package.json looks like this:

"dependencies": {
    "@capacitor-community/sqlite": "^2.4.3-1",
    "@capacitor/android": "2.4.5",
    "@capacitor/cli": "^2.0.0",
    "@capacitor/core": "^2.0.0",
    "@capacitor/share": "^1.0.4"
  }

Also, question regarding the command npm install @capacitor/share: should it be run in the project root folder, or inside src-capacitor?

Looking close at the error message, I did a
import { Plugins, Share } from '@capacitor/core'

instead of the instructed:
import { Share } from '@capacitor/share'

Is that correct? That seems to solve the install problem. However, when I execute the Share() code I get the following exception:
Web Share API not available

Not sure how to proceed here.

Found this post:

Which does
const { Share } = Plugins
instead of the instructed
import { Share } from '@capacitor/share'.

It seems to work now.

Maybe the docs need an update?

The latter is capacitor 3 syntax. The first capacitor 2. Looking at your package.json you seem to be on 2, which aligns with your own observation on what works and doesn’t.

Good catch! :slight_smile:

Does that syntax apply for all community plugins as well?

I want to use the sqlite plugin and am currently doing:
import { CapacitorSQLite } from '@capacitor-community/sqlite'
but not sure if its correct as I get an error in Android Studio on startup:

java.lang.ClassCastException: class com.getcapacitor.community.database.sqlite.CapacitorSQLite cannot be cast to com.getcapacitor.Plugin

Hi
No clue and this error might be more java then web related?

The api is defined by the plugin maintainer - the sqlite seems to have sample apps - maybe try those so to check if all is ok

Be sure to take capacitor 2 branches as u run cap2. Or migrate while u can to 3 - but that depends your current codebase and appetite

1 Like

I checked the sample apps but could only find an import of type import { useStorageSQLite } from 'vue-data-storage-sqlite-hook/dist'. However that gives a compilation error.

I updated everything to v3 today. My src-capacitor/package.json right now:

"dependencies": {
    "@capacitor-community/sqlite": "3.2.0",
    "@capacitor/android": "^3.0.0-beta.0",
    "@capacitor/app": "^1.0.3",
    "@capacitor/cli": "^3.0.0",
    "@capacitor/core": "^3.0.0",
    "@capacitor/share": "^1.0.4",
    "@capacitor/splash-screen": "^1.1.2"
  }

I contacted the plugin maintainer, thank!

1 Like