path could not be found within the project.
kuabhish opened this issue · 16 comments
I have initialized a project from react native in typescript template.
Now when I am writing these lines for import :
import { Peer, BlockStore } from '@textile/ipfs-lite';
//Use any interface-datastore compliant store;
import { MemoryDatastore } from 'interface-datastore';
import Libp2p from 'libp2p';
const store = new BlockStore(new MemoryDatastore());
Then when i do runandroid i get
Error: Unable to resolve module path
from node_modules/interface-datastore/src/utils.js
: path could not be found within the project.
What should I do?
Now i changed the store with {} -> dictionary .
But I get a new error now. which is
error: Error: Unable to resolve module
eventsfrom
node_modules/libp2p/src/index.js: events could not be found within the project.
Please help
after resolving this i am finally stuck in :
error: Error: Unable to resolve module os
from node_modules/libp2p/node_modules/libp2p-websockets/src/listener.js
: os could not be found within the project.
I have tried:
react-native link
installed node modules again ..
but nothing is working
Hi @kuabhish, looks like you are having trouble building libs for react native in general. These are common react native build issues. Please take a look here for some common fixes: https://github.com/textileio/js-threads-client/blob/master/README.md#react-native. Otherwise, you are probably better off seeking help from stackoverflow regarding general react native issues.
Sorry @carsonfarmer I did not understand what you were trying to tell me with this lin. Can you please elaborate.
I was able to build some UI with react native using RN components and a few RN libraries..
In the link that you sent me, there is rn-nodeify. Are you telling me to use it?
Yes, take a look at rn-nodeify. os
, path
etc are node modules that aren't part of standard react native modules. But also, I don't think swapping out the store with a dictionary or object is going to work for you. You need to have a datastore compliant store for backing. Please note, ipfs-lite has not be thoroughly tested in react native, so I can't guarantee it will work for you there. IPFS libraries in react native are an ongoing issue. See for example https://gitcoin.co/grants/364/react-native-support-for-ipfs
SO, What should I use as the store component?
And, Should I work on the Java API of Textile ipfs? Is it tested?
You should use something like LevelDatastore (npm i datastore-level
) or if you just need in-memory (temporary) then MemoryDatastore from interface-datastore
. Are you hoping to run 'raw' IPFS on mobile, or Textile? You might also want to take a look here: https://github.com/textileio/android-ipfs-lite or follow the work here: ipfs/js-ipfs#1254, or finally, take a look at: https://github.com/ipfs-shipyard/gomobile-ipfs (which is still early days but might provide some useful insights).
Getting this error:
`
[Mon Apr 06 2020 03:04:32.550] BUNDLE ./index.js
error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type boolean (false)
at validateString (internal/validators.js:117:11)
at Object.dirname (path.js:1128:5)
at resolveFileOrDir (/home/dragon/Documents/try/DemoTSProject/node_modules/metro-resolver/src/resolve.js:256:24)
at Object.resolve (/home/dragon/Documents/try/DemoTSProject/node_modules/metro-resolver/src/resolve.js:151:20)
at ModuleResolver.resolveDependency (/home/dragon/Documents/try/DemoTSProject/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:143:31)
at ResolutionRequest.resolveDependency (/home/dragon/Documents/try/DemoTSProject/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
at DependencyGraph.resolveDependency (/home/dragon/Documents/try/DemoTSProject/node_modules/metro/src/node-haste/DependencyGraph.js:287:16)
at Object.resolve (/home/dragon/Documents/try/DemoTSProject/node_modules/metro/src/lib/transformHelpers.js:267:42)
at /home/dragon/Documents/try/DemoTSProject/node_modules/metro/src/DeltaBundler/traverseDependencies.js:434:31
at Array.map ()
when I am writing this function . The thing is this first console.log is not being printed so i can say that it is not going in the loop.
async function run(){
console.log('in function -------------------------')
const host = new Libp2p({ ...libp2Options });
console.log('host created -------------------------')
const lite = new Peer(store, host);
console.log('node created -------------------------')
await lite.start();
const cid = 'QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u';
const data = await lite.getFile(cid);
console.log('from ipfs');
console.log(data.toString());
// Hello World
await lite.stop();
return data;
}
`
But:
function run(){ console.log('hello'); return '5'; }
When I called this function, it was working. Please help.
Can you send along a small reproducible example? In the above, what is libp2Options
? what is store
?
https://github.com/kuabhish/demo -- Please see this..
Steps i do normally:
- yarn install
- .nodemodules/.bin/rn_nodeify --hack --install
and then try to run.
I was using this : https://github.com/textileio/js-ipfs-lite#typescript
As i understand it is not able to fetch anything from node modules :
when i uncomment this:
const store = new BlockStore(new MemoryDatastore());
the same error as above shows. and i have tried many times , nothing is working.
Hello @carsonfarmer
Now I am using this https://blog.textile.io/javascript-ios-android-grpc-ipfs-lite/ your blog.
Still I am facing issues .
Now I have built a javascript template for react-native and using rn-nodeify.
I dont understand the problem
Ok i will paste the error also.
error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type boolean (false)
at validateString (internal/validators.js:117:11)
at Object.dirname (path.js:1128:5)
at resolveFileOrDir (/home/dragon/Documents/try/BAsicJS/node_modules/metro-resolver/src/resolve.js:256:24)
at Object.resolve (/home/dragon/Documents/try/BAsicJS/node_modules/metro-resolver/src/resolve.js:151:20)
at ModuleResolver.resolveDependency (/home/dragon/Documents/try/BAsicJS/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:143:31)
at ResolutionRequest.resolveDependency (/home/dragon/Documents/try/BAsicJS/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
at DependencyGraph.resolveDependency (/home/dragon/Documents/try/BAsicJS/node_modules/metro/src/node-haste/DependencyGraph.js:287:16)
at Object.resolve (/home/dragon/Documents/try/BAsicJS/node_modules/metro/src/lib/transformHelpers.js:267:42)
at /home/dragon/Documents/try/BAsicJS/node_modules/metro/src/DeltaBundler/traverseDependencies.js:434:31
at Array.map (<anonymous>)
Hi @kuabhish, thanks for sharing your issue here. What I'm seeing are a lot of possible issues. I think the best bet to just to make sure you can actually get js-libp2p working in react native (which honestly, I think is going to be tough right now). See for example https://github.com/hugomrdias/ipfs-react-native, and ipfs/devgrants#18. The long and the short of it is: I think its going to be really difficult to get libp2p, or IPFS, or ipfs-lite, etc working in React Native. So the short answer is: the problem is its really hard to get a bundle working for react native. For now, I'd recommend using something like https://github.com/openworklabs/react-native-ipfs-http-client, which connects to a remote IPFS instance, rather than trying to run IPFS on device.
Alternatively (if you really want to run IPFS on device) you're going to have to write some native code/modules, and will likely not be able to work solely in react native. Again, please take a look at the repos I've posted previously.
So to sum up, I don't think you'll get ipfs-lite to run in react native without a significant amount of work, and I am not able to provide the help you'd need to get there.
Thank you @carsonfarmer for your suggesstions and efforts.
https://blog.textile.io/javascript-ios-android-grpc-ipfs-lite/ -- (your blog) also contains the Java code.
SO I also started on Java. https://github.com/textileio/android-ipfs-lite
I found that node is not starting :
So, now the state I am in is I am not able to start the Peer.
Steps:
- copied this repo
- started this repo.
- Used debugger to find the propblem area.
private void initIPFS() {
System.out.println("in here");
try {
System.out.println("1");
Context ctx = getApplicationContext();
System.out.println("2..");
final File filesDir = ctx.getFilesDir();
System.out.println("3..");
final String path = new File(filesDir, "ipfslite").getAbsolutePath();
System.out.println("4..");
litePeer = new Peer(path, BuildConfig.DEBUG);
System.out.println("5..");
litePeer.start();
System.out.println("6..");
} catch (Exception e) {
System.out.println("errorr kumar 2");
}
The debugger output is like this:
I/System.out: in here
1
2..
I/System.out: 3..
4..
I/System.out: 5..
E/GoLog: �[0;37m15:21:49.799 INFO �[0;34m badger: �[0mAll 0 tables opened in 0s
�[0;37mlogger.go:46�[0m
I/System.out: errorr kumar 2
I/System.out: Peer not started
Please help.
looks like this became and android-ipfs-lite
issue. moved over here textileio/android-ipfs-lite#12