CCC-NULS / nuls-js

Isomorphic JavaScript SDK for NULS blockchain.
https://CCC-NULS.github.io/nuls-js/
MIT License
9 stars 8 forks source link

Error when importing nuls-js in react-native. #2

Open tudorelu opened 5 years ago

tudorelu commented 5 years ago

When trying to import nuls-js v1.0.3 in my react-native project like so:

import {Account} from 'nuls-js';

I get the following error: nulsjs-rnerror

MechJosh0 commented 5 years ago

For version 1.1.0 could you please try:

const nuls = require('nuls-js');

const Account = new nuls.Account();
const foo = Account.create();
tudorelu commented 5 years ago

Tried it, but getting the same error, at the require statement.

Since you (or someone else, maybe @amalcaraz) mentioned that it works in node and react, but not react-native, I will try using Nodejs Mobile which runs a Node.js worker in the background of the mobile app and import it through that. Will let you know about it. Of course, this is not ideal, but in the meantime it might be useful.

[EDIT] That's more complicated than I initially thought, so it will take a while.

tudorelu commented 5 years ago

Maybe it has something with the way you're deploying it to npm? I'm thinking there should be a specific procedure to publishing a react-native package to npm, a bit different than that of a nodejs package.

Here's how this person does it using webpack

MechJosh0 commented 5 years ago

So it appears that React native does struggle to run node libraries, and jimp just isn't compatible (TIL). We can remove JIMP altogether and write our own version as we're only using basic image manipulation.

I'll submit a release of this in a separate branch and we can see if this solves the problem for you for committing.

tudorelu commented 5 years ago

oh, I see. is that to do with the qr codes? Great, that'd be awesome man!! Let me know if I can help with anything.