Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Runtime Support: React-Native #1254

Closed
linonetwo opened this issue Mar 8, 2018 · 33 comments
Closed

Runtime Support: React-Native #1254

linonetwo opened this issue Mar 8, 2018 · 33 comments
Assignees
Labels
kind/resolved-in-helia kind/support A question or request for support status/deferred Conscious decision to pause or backlog

Comments

@linonetwo
Copy link

linonetwo commented Mar 8, 2018

To use IPFS on react-native, I have done following things:

  1. download https://unpkg.com/ipfs/dist/index.js instead of install from npm
  2. import core-js to polyfill set and Symbol
  3. import react-native-browser-polyfill to polyfill self
  4. use rn-nodeify to install react-native-crypto
  5. hacks like @Override for createJSModules() causes build error with RN 4.8 PeelTechnologies/react-native-os#5
  6. still can't get it run

Dragons just come one by one, can we make it easier to use js-ipfs on react-native?

Reproducible example https://github.com/linonetwo/sermover .

@RangerMauve
Copy link
Contributor

Instead of trying to run IPFS directly, check out how the browser and node versions work.

You'll want to create new versions of those files which only use features available in react-native. I think the only transport that you'll get working is libp2p-websocket-star.

React-Native is like a more constrained browser environment at the moment, and getting it anywhere as near to the node version of IPFS will require a bunch of new transports that work with RN plugins.

@mistakia
Copy link
Contributor

mistakia commented Mar 8, 2018

I was able to get ipfs and orbit-db working on react native using janeasystems/nodejs-mobile.

I had to make the following changes though:

  1. Clone and build the nodejs-mobile project in your home, so you can use the headers for building the native module (this will take a long time):
git clone https://github.com/janeasystems/nodejs-mobile ~/nodejs-mobile
pushd ~/nodejs-mobile
./tools/ios_framework_prepare.sh
popd
  1. Run npm install inside your nodejs-project using the headers from nodejs-mobile and different settings for building [email protected] for iOS (mistakia/leveldown@5cc1c2d):
GYP_DEFINES="OS=ios" npm_config_nodedir="~/nodejs-mobile" npm_config_platform="ios" npm_config_node_engine="chakracore" npm --verbose install krahimian/leveldown --build-from-source
  1. Open the iOS project in Xcode and add a "New Run Script Phase" to your target's Build Phases, containing the following Shell /bin/sh code:
/usr/bin/codesign --force --sign $EXPANDED_CODE_SIGN_IDENTITY --preserve-metadata=identifier,entitlements,flags --timestamp=none $(find "$CODESIGNING_FOLDER_PATH/nodejs-project/" -type f -name "*.node")

I used that build of leveldown for js-datastore-level and ipfs-repo. I also had to update js-datastore-level to work with [email protected] (mistakia/js-datastore-level@9545fe5)

After making those changes, I was able to initialize an ipfs repo. I'm going to do some stress testing this weekend to see how well it works.

@linonetwo
Copy link
Author

linonetwo commented Mar 9, 2018

@RangerMauve Do you mean making some tweaks to files in https://github.com/ipfs/js-ipfs/tree/master/src/core/runtime to make files like repo-rn.js ?
And why libp2p-websocket-star is difficult to deal with?

@linonetwo
Copy link
Author

@krahimian Is https://github.com/krahimian/record your project? Can I try it out?

@RangerMauve
Copy link
Contributor

@linonetwo

some tweaks to files

Yes, I think you'll want to do that if you want it to run in a RN context

And why libp2p-websocket-star is difficult to deal with?

I don't think I said it was difficult to deal with, quite the opposite. It's the only transport that can receive connections in the browser AFAIK.

By the way, @krahimian 's suggestion of using nodejs-mobile is way better than trying to get it to run in regular RN.

@mistakia
Copy link
Contributor

@linonetwo yea that's the project - there's not much to try out right now. I'll update you when there is.

The goal is to build a proof of concept twitter and soundcloud using just ipfs/orbit-db.

@daviddias daviddias added kind/support A question or request for support status/deferred Conscious decision to pause or backlog labels Mar 12, 2018
@Phactory
Copy link

@krahimian hope You succeed soon!
How about simply using: https://github.com/janeasystems/nodejs-mobile-react-native ?

@daviddias daviddias changed the title React-Native Support Runtime Support: React-Native Mar 16, 2018
@mistakia
Copy link
Contributor

I was able to get js-ipfs working on nodejs mobile (react native) both on simulator and a device (after using this fix).

However, I noticed a difference in performance and ipfs boot/start time if I add a swarm address (websocket-star).

I see there are plans for adding libp2p-connection-manager in the next release, which I think would help address performance issues on mobile.

In the meantime, does anyone have any recommendations for any settings/configurations or strategies I can try to boost performance in a mobile environment?

@linonetwo
Copy link
Author

How about https://github.com/textileio/textile-mobile 's approach? They got it worked and is MIT licensed!

@Eljoy
Copy link

Eljoy commented Sep 7, 2018

@mistakia , have you already tried all the suggestions addressing performance issues ?

@mistakia
Copy link
Contributor

mistakia commented Sep 7, 2018

Yup! 👍

Bundling the files did have a major impact on CPU usage (not just load times). After nodejs-mobile v0.1.5 and using browserify to bundle, load times and cpu usage are reasonable and the app is running smoothly.

However, I have yet to really battle test it with a large number of peers and under poor network conditions.

@Eljoy
Copy link

Eljoy commented Sep 7, 2018

@mistakia looking forward, to see your updates, thanks! 👍

@pedrouid
Copy link

pedrouid commented Jan 29, 2019

What's the status on this issue? I created a react-native project to test @mistakia's approach with nodejs-mobile but I can't get it working with versions higher than 0.31.7, get the following error with 0.34.4:

Failed : error 0:61 [61]
/private/var/containers/Bundle/Application/18B0EE12-3521-4CAD-B769-BFC01D169B41/reactnativenodejsexample.app/nodejs-project/node_modules/proper-lockfile/lib/lockfile.js:47
                    return acquireLock(file, { ...options, stale: 0 }, callback);
                                               ^^^^

SyntaxError: Expected identifier, string or number
   at createScript (vm.js:80:3)
   at runInThisContext (vm.js:139:3)
   at Module.prototype._compile (module.js:588:3)
   at Module._extensions[.js] (module.js:635:3)
   at Module.prototype.load (module.js:545:3)
   at tryModuleLoad (module.js:508:5)
   at Module._load (module.js:500:3)
   at Module.prototype.require (module.js:568:3)
   at require (internal/module.js:11:7)
   at Anonymous function (/private/var/containers/Bundle/Application/18B0EE12-3521-4CAD-B769-BFC01D169B41/reactnativenodejsexample.app/nodejs-project/node_modules/proper-lockfile/index.js:3:1)

The problem with sticking with 0.37.1 is that it includes vulnerable dependencies that have been patched already. Here is the example repo:

https://github.com/pedrouid/react-native-nodejs-example

@alanshaw
Copy link
Member

Looks like it doesnt like the object spread syntax that proper-lockfile is using.

cc @hugomrdias

@hugomrdias
Copy link
Member

hugomrdias commented Jan 30, 2019

@pedrouid from what i can see nodejs-mobile is on node 8 and we have stopped supporting that, the solution here is to bundle your js code with rollup (or whatever bundler you prefer) and pass babel-preset-env targeting node 8. this will also keep you safe from any other dependency that uses newer js syntax.

@pedrouid
Copy link

Thanks @hugomrdias, I did try bundling with both browserify and webpack using @babel/preset-env but I still got other object spread errors. I saw that nodejs-mobile plans to move to the latest nodejs version by the end of Q1 which is too long for my need so I will have to move the ipfs node to a backend.
React-native support or native implementation for mobile is definitely needed for building decentralized solutions. I will keep subscribed to this issue anyway

@hugomrdias
Copy link
Member

@pedrouid that seems weird you sure you are running babel on your dependencies? Because that should work.
Try explicitly including this plugin in babel https://babeljs.io/docs/en/babel-plugin-proposal-object-rest-spread

@pedrouid
Copy link

pedrouid commented Jan 31, 2019

Thanks, I also tried that with multiple plugins as well. You can check the branches on my test repo:

https://github.com/pedrouid/react-native-nodejs-example

I always get an error on the line that has ...trail[index] even after bundling when running nodejs-mobile

asyncMap(pathComponents.map((part, index) => ({ part, index })), ({ part, index }, cb) => {
  if (trail[index]) {
    return cb(null, {
      name: part,
      ...trail[index]
    })
  }

  // if we are not at the last path component and we are
  // not creating intermediate directories make a fuss
  if (index !== pathComponents.length - 1 && !options.parents) {
    return cb(new Error('file does not exist'))
  }

  waterfall([
    (done) => createNode(context, 'directory', options, done),
    ({ cid, node }, done) => {
      done(null, {
        cid,
        size: node.size,
        name: part
      })
    }
  ], cb)
}, cb)

@kesavananbu
Copy link

I was able to get ipfs and orbit-db working on react native using janeasystems/nodejs-mobile.

I had to make the following changes though:

  1. Clone and build the nodejs-mobile project in your home, so you can use the headers for building the native module (this will take a long time):
git clone https://github.com/janeasystems/nodejs-mobile ~/nodejs-mobile
pushd ~/nodejs-mobile
./tools/ios_framework_prepare.sh
popd
  1. Run npm install inside your nodejs-project using the headers from nodejs-mobile and different settings for building [email protected] for iOS (mistakia/leveldown@5cc1c2d):
GYP_DEFINES="OS=ios" npm_config_nodedir="~/nodejs-mobile" npm_config_platform="ios" npm_config_node_engine="chakracore" npm --verbose install krahimian/leveldown --build-from-source
  1. Open the iOS project in Xcode and add a "New Run Script Phase" to your target's Build Phases, containing the following Shell /bin/sh code:
/usr/bin/codesign --force --sign $EXPANDED_CODE_SIGN_IDENTITY --preserve-metadata=identifier,entitlements,flags --timestamp=none $(find "$CODESIGNING_FOLDER_PATH/nodejs-project/" -type f -name "*.node")

I used that build of leveldown for js-datastore-level and ipfs-repo. I also had to update js-datastore-level to work with [email protected] (mistakia/js-datastore-level@9545fe5)

After making those changes, I was able to initialize an ipfs repo. I'm going to do some stress testing this weekend to see how well it works.

Can you guys inform procedure for Android to use ipfs and ipfs-pubsub in React-Native ?
I m searched in more ways there is no proper solution and i cant use that.

@hugomrdias
Copy link
Member

@kesavananbu this is related to leveldb and not @pedrouid 's problem right ?

can't you just use another datastore instead of going through that trouble ?

@romuloalves
Copy link

romuloalves commented Mar 3, 2019

The attempt below are using nodejs-mobile-react-native.

I used zeit/ncc to compile the code of the nodejs-project, but this way the problem with the node version remains. After that I used babel to convert to Node 8.

Running the compiled script in my computer with Node 8.6 works. In the React Native side I always receive the error below:

*/Backoff.prototype.setJitter=function(jitter){this.jitter=jitter;};/***/},/***/2453:/***/function(module,__unusedexports,__webpack_require__){/* Copyright (c) 2017 Rod Vagg, MIT License */var xtend=__webpack_require__(6667);var AbstractIterator=__webpack_require__(3701);var AbstractChainedBatch=__webpack_require__(6356);var hasOwnProperty=Object.prototype.hasOwnProperty;var rangeOptions='start end gt gte lt lte'.split(' ');function AbstractLevelDOWN(location){if(!arguments.length||location===undefined){throw new Error('constructor requires at least a location argument');}if(typeof location!=='string'){throw new Error('constructor requires a location string argument');}this.location=location;this.status='new';}AbstractLevelDOWN.prototype.open=function(options,callback){var self=this;var oldStatus=

SyntaxError: Invalid character
   at createScript (vm.js:80:3)
   at runInThisContext (vm.js:139:3)
   at Module.prototype._compile (module.js:588:3)
   at Module._extensions[.js] (module.js:635:3)
   at Module.prototype.load (module.js:545:3)
   at tryModuleLoad (module.js:508:5)
   at Module._load (module.js:500:3)
   at Module.runMain (module.js:665:3)
   at startup (bootstrap_node.js:188:9)
   at Anonymous function (bootstrap_node.js:611:3)

Before the experiment I described above I tried using noderify + babel but I received the same Invalid character error in a different part of the code.

@romuloalves
Copy link

OK, the problem about Invalid character is because of human-to-milliseconds, this bug: https://github.com/hacdias/human-to-milliseconds/issues/1. I fixed it like described in the bug.

Now, it's partially working. The nodejs side is not breaking the app but it's not executing nothing after I create the node: e.g. const ipfs = new IPFS(ipfsConfig);.

@mistakia
Copy link
Contributor

mistakia commented May 23, 2019

I'm able to get version 0.34.4 (as thats the latest working version with ipfs-log/OrbitDB) running on version 0.4.1 of nodejs-mobile-react-native which ships with node 10.13.0. I'm still needing to browserify and babilify for performance reasons and to avoid the issues @pedrouid was seeing. Also, I'm still patching the human-to-milliseconds package.

browserify -o bundle.js -g [ babelify --presets [ @babel/preset-env --targets [ --node 10.13.0 ] ] ] --node --im -u 'leveldown' main.js

Everything works when no repo exists. However, when starting ipfs after a repo has been created/initialized from a previous time, I get this runtime issue:

runtime log
  �[35;1mlibp2p:switch:dialer �[0mcreate: 8 peer limit, 30000 dial timeout �[35m+0ms�[0m
2019-05-23T17:07:32.107Z libp2p:connection-manager options: {"maxPeers":10,"minPeers":2,"maxData":null,"maxSentData":null,"maxReceivedData":null,"maxEventLoopDelay":null,"pollInterval":20000,"movingAverageInterval":60000,"defaultPeerValue":1,"maxPeersPerProtocol":{}}
  �[32;1mlibp2p �[0mlibp2p is starting �[32m+0ms�[0m
  �[33;1mlibp2p:switch:transport �[0madding undefined �[33m+0ms�[0m
  �[31;1mlatency-monitor:LatencyMonitor �[0mlatencyCheckIntervalMs: 500 dataEmitIntervalMs: 20000 �[31m+0ms�[0m
  �[31;1mlatency-monitor:LatencyMonitor �[0mExpecting ~0.025 events per summary �[31m+1ms�[0m
  �[31;1mlatency-monitor:LatencyMonitor �[0mUsing process.hrtime for timing �[31m+3ms�[0m
  �[31;1mlatency-monitor:LatencyMonitor �[0mlocalData: { deltaOffset: �[33m472�[39m, startTime: [ �[33m59260�[39m, �[33m755249010�[39m ] } �[31m+0ms�[0m
  �[34;1mlibp2p:switch �[0mThe switch is starting �[34m+0ms�[0m
  �[35;1mlibp2p:websocket-star:multi �[0mlisten on 0 server(s) with id QmbrymfSbFvBDqyXnCvY7Pktd11JV7J9CYYx1d7gnnoaBd �[35m+0ms�[0m
  �[34;1mlibp2p:switch �[0mThe switch has started �[34m+4ms�[0m
  �[33;1mlibp2p:switch:transport �[0madding _class �[33m+13ms�[0m
  �[34;1mlibp2p:mdns �[0mquery ipfs.local �[34m+0ms�[0m
  �[32;1mlibp2p:floodsub �[0mstarting �[32m+0ms�[0m
  �[32;1mlibp2p:floodsub �[0mstarted �[32m+1ms�[0m
  �[32;1mlibp2p �[0mlibp2p has started �[32m+33ms�[0m
Error: multihash length inconsistent: 0x59948439065f29619ef41280cbb932be52c56d99c5966b65e0111239f098bbef0000000000000a020801000000002f434951465446454548454446364b4c42543332424641474c58455a4c345557464e574d344c46544c4d5851424345525a36434d4c58335958330000000000002f583300000000002f58332f434951465446454548454446364b4c42543332424641474c58455a4c345557464e574d344c46544c4d5851424345525a36434d4c583359000000000058330000000000002f5833000000000001000000000000000170122059948439065f29619ef41280cbb932be52c56d99c5966b65e0111239f098bbef000000002f414659424549435a53534344534253374646515a3535415351444633534d56364b4c435733474f46535a56574c59415243493437424746333534000000000033350000000000002f333500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002f33352f414659424549435a53534344534253374646515a3535415351444633534d56364b4c435733474f46535a56574c59415243493437424746333534000033350000000000002f333500000000002f434951465446454548454446364b4c42543332424641474c58455a4c345557464e574d344c46544c4d5851424345525a36434d4c58335958330000000000002f583300000000002f58332f434951465446454548454446364b4c42543332424641474c58455a4c345557464e574d344c46544c4d5851424345525a36434d4c583359000000000058330000000000002f5833000000000058330000000000002f583300000000002f58332f434951465446454548454446364b4c42543332424641474c58455a4c345557464e574d344c46544c4d5851424345525a36434d4c583359000000000058330000000000002f58330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
   at validateCID (/Users/user/Library/Developer/CoreSimulator/Devices/8541E74C-DEED-48CC-95AD-E2C1BA2A5C56/data/Containers/Bundle/Application/C3F7A556-34BB-42B6-BB94-7E47A44963EC/Record.app/nodejs-project/bundle.js:53951:9)
   at CID (/Users/user/Library/Developer/CoreSimulator/Devices/8541E74C-DEED-48CC-95AD-E2C1BA2A5C56/data/Containers/Bundle/Application/C3F7A556-34BB-42B6-BB94-7E47A44963EC/Record.app/nodejs-project/bundle.js:53792:5)
   at _class (/Users/user/Library/Developer/CoreSimulator/Devices/8541E74C-DEED-48CC-95AD-E2C1BA2A5C56/data/Containers/Bundle/Application/C3F7A556-34BB-42B6-BB94-7E47A44963EC/Record.app/nodejs-project/bundle.js:54015:7)
   at Anonymous function (/Users/user/Library/Developer/CoreSimulator/Devices/8541E74C-DEED-48CC-95AD-E2C1BA2A5C56/data/Containers/Bundle/Application/C3F7A556-34BB-42B6-BB94-7E47A44963EC/Record.app/nodejs-project/bundle.js:123637:7)
   at Anonymous function (/Users/user/Library/Developer/CoreSimulator/Devices/8541E74C-DEED-48CC-95AD-E2C1BA2A5C56/data/Containers/Bundle/Application/C3F7A556-34BB-42B6-BB94-7E47A44963EC/Record.app/nodejs-project/bundle.js:67314:9)
   at Anonymous function (/Users/user/Library/Developer/CoreSimulator/Devices/8541E74C-DEED-48CC-95AD-E2C1BA2A5C56/data/Containers/Bundle/Application/C3F7A556-34BB-42B6-BB94-7E47A44963EC/Record.app/nodejs-project/bundle.js:164827:5)
   at Anonymous function (/Users/user/Library/Developer/CoreSimulator/Devices/8541E74C-DEED-48CC-95AD-E2C1BA2A5C56/data/Containers/Bundle/Application/C3F7A556-34BB-42B6-BB94-7E47A44963EC/Record.app/nodejs-project/bundle.js:78600:5)
  �[31;1mlatency-monitor:LatencyMonitor �[0mlocalData: { deltaOffset: �[33m491�[39m, startTime: [ �[33m59261�[39m, �[33m234567562�[39m ] } �[31m+477ms�[0m
  �[31;1mlatency-monitor:LatencyMonitor �[0mMS: 8.281317999999998 Data: { startTime: [ �[33m59260�[39m, �[33m754911051�[39m ],
  �[31;1mlatency-monitor:LatencyMonitor �[0m  minMs: �[33m8.281317999999998�[39m,
  �[31;1mlatency-monitor:LatencyMonitor �[0m  maxMs: �[33m8.281317999999998�[39m,
  �[31;1mlatency-monitor:LatencyMonitor �[0m  events: �[33m1�[39m,
  �[31;1mlatency-monitor:LatencyMonitor �[0m  totalMs: �[33m8.281317999999998�[39m } �[31m+1ms�[0m
  �[31;1mlatency-monitor:LatencyMonitor �[0mlocalData: { deltaOffset: �[33m498�[39m, startTime: [ �[33m59261�[39m, �[33m730555939�[39m ] } �[31m+495ms�[0m

bundle.js referenced in the stacktrace.

To save some time, I've tracked it down to this line:
https://github.com/ipfs/js-ipfs-mfs/blob/v0.8.0/src/core/utils/with-mfs-root.js#L39

ipfs remains in the starting state. Any insights or suggestions are greatly appreciated.

Update: passing in { preload: { enabled: false } } bypasses the runtime issue. Seems to be related to preload-mfs.

Update: ipfs config:
{
    init: {
      bits: 1024,
      emptyRepo: true,
      log: sendState
    },
    repo: path.resolve(recorddir, './ipfs'),
    preload: {
      enabled: false
    },
    EXPERIMENTAL: {
      dht: false, // TODO: BRICKS DEVICE
      pubsub: true
    },
    config: {
      Bootstrap: [],
      Addresses: {
	    Swarm: [
          '/ip4/0.0.0.0/tcp/4002',
          '/ip4/0.0.0.0/tcp/4003/ws',
          '/ip4/159.203.117.254/tcp/9090/ws/p2p-websocket-star'
	    ]
      }
    },
    libp2p: {
      config: {
        relay: {
          enabled: false
        }
      }
    },
    connectionManager: {
      maxPeers: 10,
      minPeers: 2,
      pollInterval: 20000 // ms
    }
  }

@arminsal1
Copy link

@mistakia I tried all of your fixes and I keep getting the following error:

/Users/Username/Library/Developer/CoreSimulator/Devices/F7B46EA3-1AE3-4DF2-B02E-81A54CDDC694/data/Containers/Bundle/Application/66E4C6E1-FB32-4E2F-936C-E585D6D64EC0/VIVA.app/nodejs-project/node_modules/proper-lockfile/lib/lockfile.js:61
                    return acquireLock(file, { ...options, stale: 0 }, callback);
                                               ^^^^

SyntaxError: Expected identifier, string or number
   at Script (vm.js:87:7)
   at createScript (vm.js:251:3)
   at runInThisContext (vm.js:303:3)
   at Module.prototype._compile (internal/modules/cjs/loader.js:656:3)
   at Module._extensions[.js] (internal/modules/cjs/loader.js:699:3)
   at Module.prototype.load (internal/modules/cjs/loader.js:598:3)
   at tryModuleLoad (internal/modules/cjs/loader.js:537:5)
   at Module._load (internal/modules/cjs/loader.js:529:3)
   at Module.prototype.require (internal/modules/cjs/loader.js:636:3)
   at require (internal/modules/cjs/helpers.js:20:7)

Any idea how to fix this error specifically?

@mistakia
Copy link
Contributor

I believe the babelify transform for browserify should fix this. See my previous comment for the full command. I used the @babel/preset-env preset and passed in the node target. Also note that I ran the browserify transform with -g and not -t otherwise it won't transform stuff in node_modules.

@arminsal1
Copy link

arminsal1 commented May 30, 2019

@mistakia Thanks for the tip! Is it normal for it to attempt to transform the node_modules in the root of my project outside of the the nodejs-project folder?

Also do I run the babelify command in the root of my entire project or in the nodejs-project directory?

@mistakia
Copy link
Contributor

You want to run browserify/babelify in ./nodejs-assets/nodejs-project/ in which case it shouldnt be accessing anything in the node_modules in the root of the project.

@arminsal1
Copy link

@mistakia That's what I thought, but for some reason I'm getting conflict errors from libraries like @react-native-community/react-native-asyncstorage in the node_modules folder of my project's root. I'm just copying and pasting this line in the nodejs-project folder:

browserify -o bundle.js -g [ babelify --presets [ @babel/preset-env --targets [ --node 10.13.0 ] ] ] --node --im -u 'leveldown' main.js

When I remove those the libraries in my root node_modules the command finishes without errors but doesn't seem to change anything, which leads me to believe it's not affecting my nodejs-project folder for some reason?

@arminsal1
Copy link

I don't know if this has to do with my issue, but I'm getting

[BABEL] Note: The code generator has deoptimised the styling of /Users/Admin/Documents/APP/nodejs-assets/nodejs-project/node_modules/lodash/lodash.js as it exceeds the max of 500KB.

before the script attempts to work on the project root's modules in APP/node_modules

@notatestuser
Copy link

I don't know if this has to do with my issue, but I'm getting

[BABEL] Note: The code generator has deoptimised the styling of /Users/Admin/Documents/APP/nodejs-assets/nodejs-project/node_modules/lodash/lodash.js as it exceeds the max of 500KB.

before the script attempts to work on the project root's modules in APP/node_modules

Seeing the same here with the latest nodejs-mobile and libp2p dependencies. A lot of things seem to depend on lodash though. Maybe there's a way to make Babel avoid processing this file?

@RobertFischer
Copy link

Don't worry about that [BABEL] Note: message. It's just saying that it's stopped trying to track the styling information because the file is too big.

@emclab
Copy link

emclab commented Feb 5, 2020

I am seting up IPFS 0.4.0 with nodejs-mobile-react-native 0.5.0 on MacOS. But always failed with build when launch npx react-native run-ios. Here is my issue post. The React Native version is 0.61.5 and 3 node version 10.13.0/10.16.0/10.17.0 all failed with launch build. It is related to node-gyp and I am not sure what exactly is wrong.

Any suggestion about how to fix?

@SgtPooki
Copy link
Member

js-ipfs is being deprecated in favor of Helia. You can #4336 and read the migration guide.

Please feel to reopen with any comments by 2023-06-02. We will do a final pass on reopened issues afterwards (see #4336).

I completely agree that we want IPFS to be able to run in react-native flawlessly. I believe this is possible with Helia, as we've already "proven" that we can "almost" replace public gateways with in-app service workers. Please try out Helia and let us know if you run into issues when using it in React-Native!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/resolved-in-helia kind/support A question or request for support status/deferred Conscious decision to pause or backlog
Projects
No open projects
Status: Done
Development

No branches or pull requests