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

Support cordova-cli 9.0.0 - requireCordovaModule deprecation #56

Closed
tombell opened this issue Mar 25, 2019 · 16 comments · Fixed by #57
Closed

Support cordova-cli 9.0.0 - requireCordovaModule deprecation #56

tombell opened this issue Mar 25, 2019 · 16 comments · Fixed by #57

Comments

@tombell
Copy link

tombell commented Mar 25, 2019

The use of context.requireCordovaModule for non-cordova dependencies has been removed, and suggests you now add the dependency to the plugins package.json and require'd normally.

apache/cordova-lib#707

@lrbalt
Copy link

lrbalt commented Mar 27, 2019

manually changing context.requireCordovaModule into plain require gives another error: context.vaModule is not a function. This occurs on line 13614 of add-swift-support.js: var glob = context.vaModule('glob');. Any idea how to fix this?

@brainssolutions
Copy link

@lrbalt The problem is encountered when the new [email protected] version does not support the required file upload through that command.

Just go to "Projectroot\plugins\cordova-plugin-add-swift-support" and open the file add-Swift-support. js replacing the old command:

"context. requireCordovaModule" with-> require

I also found that on the line:

-> 12920: var cordovaUtil = context. requireCordovaModule (' Cordova-lib/src/Cordova/util ');

While changing the method as shown above, the CLI of Cordoba returns an error. I reset the old variable and added the iOS platform again.

It worked For me.

@timbru31
Copy link
Contributor

timbru31 commented Mar 27, 2019

I'm currently working on a PR to update fix this issue (and to update the dependencies and drop webpack)

Edit: #57

@akofman
Copy link
Owner

akofman commented Mar 27, 2019

Hello guys,

Thanks a lot for you PR @timbru31, I'm not working on a Cordova project anymore at the moment so it's really appreciated to have this kind of PR. I will have a look on it this week.
@brainssolutions, @lrbalt and @tombell could you please check the Tim's PR and return me if it works for you ? It will help a lot.

@tombell
Copy link
Author

tombell commented Mar 27, 2019

@akofman Yup, I'll give it a try when I return to work tomorrow 👍

@lrbalt
Copy link

lrbalt commented Mar 28, 2019

changing all requireCordovaModule with plain require works. I made a typo, so forget about the other error I reported.

@lrbalt
Copy link

lrbalt commented Mar 28, 2019

I just used PR #57 and my app compiles with latest xcode. I needed to manually set minimum swift version to 4, but I don't know if this plugins depends on swift 3 or another one. I'm in favor of merging

@akofman
Copy link
Owner

akofman commented Mar 28, 2019

@lrbalt you should be able to configure this version using <preference name="UseSwiftLanguageVersion" value="4" /> in your config.xml. Did you try this ?

@lrbalt
Copy link

lrbalt commented Mar 28, 2019

I do not have this preference in my config.xml, but I edited it in Xcode. That works.

I think it is set in the xcode-config if nothing is defined anywhere. I think it is set to 3 on line 148 of add-swift-support.js (the one of PR #57). Perhaps it should be changed to 4 since Xcode 10.2 does not support 3 anymore?

@timbru31
Copy link
Contributor

timbru31 commented Mar 28, 2019 via email

@byronaltice
Copy link

byronaltice commented Mar 28, 2019

changing all requireCordovaModule with plain require works. I made a typo, so forget about the other error I reported.

Could you provide me some guidance? I've cloned timbru31's fix, how can I replace the old cordova plugin with the impromptu code?

e.g.: someone else clones my repo, they don't have my node_modules so... how can they get the code fix?

@lrbalt
Copy link

lrbalt commented Mar 28, 2019

AFAICS, two options:

  1. use the PR refactor: update tooling, add support for Cordova v9 #57 - I copied all files from that branch to my plugins/cordova-plugin-add-swift-support
  2. do a search-and-replace for context.requireCordovaModule and replace with require

The third option is wait for #57 to be merged of course :-)

When everything is merged, you may need to remove the changed plugin and reinstall the official updated plugin

@byronaltice
Copy link

Thanks @lrbalt !

@lrbalt
Copy link

lrbalt commented Apr 3, 2019

please note that if you manually changed the plugin, it will not be removed using cordova plugin rm. It will leave your changed plugin in plugins/cordova-add-swift-support. I needed to manually remove it in order to be able to add the newly released plugin.

also, I needed to rebuild the ios workspace by cordova platform remove ios and add it again using cordova platform add ios. This solved missing method errors in the ios simulator for me for another plugin that uses this one.

@JPAlfa
Copy link

JPAlfa commented Nov 26, 2019

As mentioned on this Issue, I'm still having problem with this requireCordovaModule. Am I the only one?

@jfoclpf
Copy link

jfoclpf commented Sep 21, 2020

How do I access require from the hooks script context?

module.exports = function (context) {
  console.log(context.hook)

  var q =  context.requireCordovaModule('q') // does not work
  var q = context.q // does not work
  var q = context.require('q') // does not work
  var q = context.cordova.require('q') // does not work
}

Or shall I simply ignore the context altogether in the hooks?

module.exports = function (context) {
  console.log(context.hook)
  var q =  require('q') // this works, but what about the context?
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants