Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work in react-native (because it uses node.js libraries) #45

Closed
Syed-Kashan-Adil opened this issue May 21, 2019 · 11 comments
Closed

Comments

@Syed-Kashan-Adil
Copy link

Unable to resolve module path from /Users/mtahir/Desktop/scuttlebut/node_modules/ssb-client/index.js: Module path does not exist in the Haste module map

@christianbundy
Copy link
Contributor

Hey @Syed-Kashan-Adil, sorry to hear you're running into a bug.

Could you describe how you're running this code or give instructions on how to reproduce the problem? I'm not familiar with that error message, although I've found some info here: zetachang/react-native-dotenv#39

@Syed-Kashan-Adil
Copy link
Author

I am just importing ssb-client and call it. Code gets crash with above mentioned error.
Code:

const ssbClient = require("ssb-client");
componentDidMount(){
ssbClient((err,sbot) => {
if(err){
throw(err)
}
sbot.publish({
type :"post",
text : "Hello World"
}, (err,msg) => {
console.log(msg);
})

})
}

@christianbundy christianbundy changed the title unable to resolve module path Does not work in browser (because it uses node.js libraries) May 28, 2019
@christianbundy
Copy link
Contributor

I see the componentDidMount() which makes me think you're using this in a browser.

cc: @dominictarr, this is meant to work in a browser as well yeah?

@Syed-Kashan-Adil
Copy link
Author

I am working on react native. Can I run this on node js mobile?

@christianbundy
Copy link
Contributor

I believe so, but I'm not sure.

@Syed-Kashan-Adil
Copy link
Author

Ok. Thank u so much

@ahdinosaur
Copy link

hm, looks like this would be a problem using ssb-client with React Native's JavaScript bundler: Metro

from my perspective, at the moment the Scuttlebutt stack only explicitly supports the browserify JavaScript bundler, but is worth checking out how Manyverse got ssb-client working.

@Syed-Kashan-Adil: is it possible for you to publish a reproducible example that we could play with, to see the error in detail and explore how we might get things working?

@ahdinosaur
Copy link

looking at Manyverse, as far as i can tell there the core Scuttlebutt stack runs inside nodejs-mobile-react-native as the "backend", where in the "frontend" code re-implements functionality similar to ssb-client but without using any modules from the Node.js standard library (like path, the module used here).

looks like this could be a possible solution: https://github.com/philikon/ReactNativify:

The React Native packager has a little known pluggable component called a transformer. This is a function that takes a given source file and (typically using Babel) transforms it so that all the funky ES2015 syntax is replaced with stuff that JavaScriptCore can parse. We can supply our own transformer, use a Babel helper called babel-plugin-rewrite-require, and include browserify's reimplementation of node's core libraries to make any piece of code originally written for node.js runnable inside React Native's environment.

/cc @staltz

@dominictarr dominictarr changed the title Does not work in browser (because it uses node.js libraries) Does not work in react-native (because it uses node.js libraries) May 29, 2019
@dominictarr
Copy link
Contributor

yes, browserify put a huge engineering effort in to make node style modules work in the browser. (I did some of that work). browserify works for most ssbc modules, so hopefuly that babel plugin works.

@staltz
Copy link
Member

staltz commented May 29, 2019

Two modules are fundamental to enable using ssb client libraries in React Native:

@stale
Copy link

stale bot commented Aug 27, 2019

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

@stale stale bot added the stale label Aug 27, 2019
@stale stale bot closed this as completed Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants