Plugin development : Error: Cannot find module 'xcode'

Hello, i am trying to integrate an Ios plugin (javascript with a swift file) on P10.0.907.0.
Unfortunally every time i try to build the IOS app, its simple return (Error: Cannot find module 'xcode')

To be sure, i build an cordova Ios App, in Mac, using the plugin, and tested it on device, and everything OK.

Whats is the issue with this error? There isnt any clear information about it. And "npm install --save xcode" doesnt solve it. Even in my gitlab, i assure there is a node module called Xcode, but still i am unable to build it.

Any solutions? I am really unable to proceede for days.

With best regards,
Slavi

Hi Slavi, I'm guessing that the plugin you're trying to use has cordova hooks. One of those hooks depends on the "xcode" package, right?

Well, i dont think so João, there isnt any hook in the plugin.xml  (at least from my understandment)

you can see the plugin:
https://gitlab.com/slavipopov/cordova-plugin-motion

This plugin basically is JS promise function, which calls a function in the swift file. This function just opens a particular app, and the app, returns to my app the data from the Promise js function already processed.

i am not very experienced in mobile.

Solution

You're right, the problem is not directly your plugin but instead the dependency that you have from cordova-plugin-add-swift-support which in turn depends on "xcode".


Can you give it a try and use an older version of the cordova-plugin-swift-support plugi, specifically version 1.7.2 which packs the xcode dependency? Basically you just need to change on your plugin.xml from:


<dependency id="cordova-plugin-add-swift-support"/>

to:

<dependency id="cordova-plugin-add-swift-support@1.7.2"/>


Hopefully this solves the problem :)


Regards,

João Gonçalves

Solution

Hi Slavi,

Can you to share how to do this "integrate an Ios plugin (javascript with a swift file)", please?

What path you're trying? Is it like the way to create a plugin that there is on the learn session?


Tks,

Leandro.

Leandro Correa wrote:

Hi Slavi,

Can you to share how to do this "integrate an Ios plugin (javascript with a swift file)", please?

What path you're trying? Is it like the way to create a plugin that there is on the learn session?


Tks,

Leandro.

Well yes, at the end of the day, each plugin consist on:
 "Src" folder -> containing all native code for each platform. (IOS, Android, and etc.)
"www" folder -> with javascript  calling the native function.
plugin.xml -> containing information about how you gonna call the javascript, also called clobbers,  also you define other properties, like dependencies, URL schemes, and the paths to the native files.
then you have package.json, where you specify some general info.

in this link, Stanley explain very well (unfortunally for android)
https://www.outsystems.com/blog/posts/how-to-create-a-cordova-plugin-from-scratch/
but the principles are the same.

PS: If you want to test ios plugin, you need a Mac, with Safari, otherwise you cant inspect the JS.
And forget about native debugging unless you build the plugin, create a test project with xcode, and then debug.




Thank you so much!