Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

[QUESTION] cordova.js imports, RN 4.6 #42

Open
mribbons opened this issue Jul 10, 2017 · 8 comments
Open

[QUESTION] cordova.js imports, RN 4.6 #42

mribbons opened this issue Jul 10, 2017 · 8 comments

Comments

@mribbons
Copy link
Contributor

Hi,
I have started work to get this module working with RN 4.6, see here:
mribbons@2eebb79

The Java side seems to initialise OK, I have got around null reference exceptions, the commit is self explanatory.

I am now having an issue with the cordova.js file:

error: bundling failed: "Unable to resolve module `cordova/utils` from 
`d:\\myProject\\node_modules\\react-native-cordova-plugin\\platforms\\android\\assets\\www\\cordova.js`: 
Module does not exist in 
the module map\n\nThis might be related to 
https://github.com/facebook/react-native/issues/4968\n
To resolve try the following:\n  1. Clear watchman watches: `watchman watch-del-all`.\n
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n
  3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cache`."

I have checked the github link and it is unrelated.

It seems that cordova/utils is defined later in the file. If I remove

var utils = require('cordova/utils');

It seems to work, but then has similar issues with all of the other requires, all of which are defined in the file apart from cordova/plugin_list.

It seems as though the cordova.define() calls are failing for some reason,

I'm wondering if this is to do with RN changes, or the cordova.js file itself.

I have tried rebuilding the file to no avail.

At first I was using this plugin:
cordova-plugin-cipherlab-rs30

but I have since removed it and I still get the same issues.

@mribbons
Copy link
Contributor Author

I have done a bit more investigation and playing with the platform/assets/www/cordova.js file.

It seems as though it expects cordova.define() to work with the global require(), but that isn't the case.

Something I don't understand is that inside cordova.define("cordova/utils") there is a call to require("cordova/utils"). This seems like a circular reference.

Were the modules require()'d in cordova.js previously defined somewhere else that is no longer being included, I wonder? eg in another module.

@theBliz
Copy link

theBliz commented Jul 20, 2017

@mribbons thanks for the patch for RN 4.6 :) did you manage to understand this issue also?

@mribbons
Copy link
Contributor Author

Hi @theBliz, I couldn't get it to work. I have walked away from it for now.

@theBliz
Copy link

theBliz commented Jul 20, 2017

I've been able to import cordova-plugin-camera and now I'm having an issue with importing https://github.com/mattrayner/cordova-plugin-vuforia and some error related with cordova pops out Execution failed for task ':cordovaplugin:mergeReleaseResources'.

By any chance did you have something similar?

@mribbons
Copy link
Contributor Author

mribbons commented Jul 20, 2017

@theBliz nope, I couldn't get any plugins to work. I added cordova-plugin-cipherlab-rs30 then removed it, then I got the issues with cordova.js, as above.

Is cordova-plugin-camera functional after importing?

@theBliz
Copy link

theBliz commented Jul 20, 2017

I still have to try it on the device, but it's building.

This is the default class in my index.android.js

`export default class test001 extends Component {

var Cordova = require('react-native-cordova-plugin');

Cordova.navigator.camera.getPicture(onSuccess, onFail, {sourceType: Cordova.Camera.PictureSourceType.SAVEDPHOTOALBUM)});

// Listen to cordova-plugin-network-information plugin's events
Cordova.addEventListener('offline', onEvent);

render() {
return (


Welcome to React Native!


To get started, edit index.android.js


Double tap R on your keyboard to reload,{'\n'}
Shake or press menu button for dev menu


);
}
}`

what you think?

@mribbons
Copy link
Contributor Author

@theBliz Looks promising.

Let me know how it goes on device, make sure you wire up the camera function and test it out.

Full disclaimer, I don't have time to work on this now but I may come back to it.

I was going to use this plugin for cordova sql, but someone has already ported it to RN anyway. I think that will happen with other plugins as RN users need them. I'm not sure of the usage stats on RN vs cordova but it wins out in terms of development speed and performance, so I think cordova might not survive.

@axemclion - Can you comment?

@salmon-charles
Copy link

For me to work I had to replace all the require("xxx") by cordova.require("...")
(I kept the require(varName) as it)

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

No branches or pull requests

3 participants