ionic-team / create-capacitor-plugin

Create a new Capacitor plugin ⚡️
Other
74 stars 11 forks source link

No such module 'Capacitor' #109

Open jafaircl opened 1 month ago

jafaircl commented 1 month ago

I'm following the docs here for creating a plugin:

https://capacitorjs.com/docs/plugins/creating-plugins

When I run npm init @capacitor/plugin@latest, everything seems to be created fine. But, when I open the package in Xcode, I get an error No such module 'Capacitor' when I open the plugin .swift file. The package fails to build. I don't make any changes before attempting to build the plugin.

I'm on Xcode version 15.4 and node 20.13.1

(There is also an issue building the web version but that is because of type errors in the dependencies. Setting "skipLibCheck": true and "types": [] in the compiler options in tsconfig.json fixes that issue)

jafaircl commented 1 month ago

I think I tracked down the root issue. In Xcode the build destination was selected as "My Mac" under Product > Destination. This caused an error in Capacitor that says "While building for macOS, no library for this platform was found in {{ build directory }}". Setting the build destination as "Any iOS Device" under Product > Destination allowed me to build the plugin with no errors. I'm on a M2 Mac so maybe it's an Apple silicon issue. I'll leave this issue open so others can find it and/or you can add it to the docs if you see fit. Feel free to close once you decide. Thanks!