Friday, March 30, 2018

Porting nodejs module to React Native: Object.prototype undefined

Leave a Comment

Here's my source tree at the exact moment of the problem:

https://github.com/lucaszanella/jscam/tree/cf29b3cc90df7c5c7bb2d27c2205264d52b0715d/src/jscam

I believe npm install, npm start and npm run android will make it launch (note that onvif is not installed from npm but cloned in npm post-install script and then installed, but it gets installed in node_modules with a symlink to the place where it cloned. I even tried to put everything in node_modules just in case, but the error persists). Also don't mind the extra docker things I have in the folder

Anyways, the problem is:

I'm trying to use the nodejs module onvif in React Native, so I used this technique to translate the require methods using babel and installed browserfy modules to implement the core nodejs modules. I've tested with simple examples like crypto and it worked. However, when I try to simply import the onvif module I get this:

enter image description here

Here's device.js line 30, looks like Cam is undefined here

When I import the onvif.js which imports cam.js, nothing happens. But then it imports device.js which seems to be getting undefined when importing cam.js again

I also tried this method which seems to avoid all the babel translation but surprisingly the problem persists.

UPDATE:

Here's the new source tree: https://github.com/lucaszanella/jscam/tree/98b714219ed25b9d91ea3af275177f66fdb74fa2/src/jscam

I'm now using extraNodeModules which is the official way to do. You can see my dependencies here: https://github.com/lucaszanella/jscam/blob/98b714219ed25b9d91ea3af275177f66fdb74fa2/src/jscam/rn-cli.config.js

Now the error changed: enter image description here

It's on this line: https://github.com/isaacs/sax-js/blob/d65e3bb5049893aaab4aba05198b9cd335b5a1ad/lib/sax.js#L222

It still looks like the same type of error though

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment