ipfs / js-ipfs

IPFS implementation in JavaScript
https://js.ipfs.tech
Other
7.44k stars 1.25k forks source link

Runtime Support: React-Native #1254

Closed linonetwo closed 1 year ago

linonetwo commented 6 years ago

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 https://github.com/PeelTechnologies/react-native-os/issues/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 commented 6 years ago

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 commented 6 years ago

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
  2. Run npm install inside your nodejs-project using the headers from nodejs-mobile and different settings for building leveldown@3.0.0 for iOS (krahimian/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
  3. 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 leveldown@3.0.0 (krahimian/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 commented 6 years ago

@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 commented 6 years ago

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

RangerMauve commented 6 years ago

@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 commented 6 years ago

@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.

Phactory commented 6 years ago

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

mistakia commented 6 years ago

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 commented 6 years ago

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

Eljoy commented 5 years ago

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

mistakia commented 5 years ago

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 commented 5 years ago

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

pedrouid commented 5 years ago

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 commented 5 years ago

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

cc @hugomrdias

hugomrdias commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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 leveldown@3.0.0 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 leveldown@3.0.0 (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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 ``` libp2p:switch:dialer create: 8 peer limit, 30000 dial timeout +0ms 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":{}} libp2p libp2p is starting +0ms libp2p:switch:transport adding undefined +0ms latency-monitor:LatencyMonitor latencyCheckIntervalMs: 500 dataEmitIntervalMs: 20000 +0ms latency-monitor:LatencyMonitor Expecting ~0.025 events per summary +1ms latency-monitor:LatencyMonitor Using process.hrtime for timing +3ms latency-monitor:LatencyMonitor localData: { deltaOffset: 472, startTime: [ 59260, 755249010 ] } +0ms libp2p:switch The switch is starting +0ms libp2p:websocket-star:multi listen on 0 server(s) with id QmbrymfSbFvBDqyXnCvY7Pktd11JV7J9CYYx1d7gnnoaBd +0ms libp2p:switch The switch has started +4ms libp2p:switch:transport adding _class +13ms libp2p:mdns query ipfs.local +0ms libp2p:floodsub starting +0ms libp2p:floodsub started +1ms libp2p libp2p has started +33ms 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) latency-monitor:LatencyMonitor localData: { deltaOffset: 491, startTime: [ 59261, 234567562 ] } +477ms latency-monitor:LatencyMonitor MS: 8.281317999999998 Data: { startTime: [ 59260, 754911051 ], latency-monitor:LatencyMonitor  minMs: 8.281317999999998, latency-monitor:LatencyMonitor  maxMs: 8.281317999999998, latency-monitor:LatencyMonitor  events: 1, latency-monitor:LatencyMonitor  totalMs: 8.281317999999998 } +1ms latency-monitor:LatencyMonitor localData: { deltaOffset: 498, startTime: [ 59261, 730555939 ] } +495ms ```

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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 1 year ago

js-ipfs is being deprecated in favor of Helia. You can https://github.com/ipfs/js-ipfs/issues/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 https://github.com/ipfs/js-ipfs/issues/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!