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

Support for react-native #132

Open
aliassarpro opened this issue Oct 30, 2019 · 4 comments
Open

Support for react-native #132

aliassarpro opened this issue Oct 30, 2019 · 4 comments

Comments

@aliassarpro
Copy link

aliassarpro commented Oct 30, 2019

Hi,
I think it is so painful that such a useful module can't be implemented in react-native.

What I did:
I made a blank project with react native and used the module just like every other api:

import {
	View,
} from 'react-native';
var EventSource = require('eventsource')
export default class App extends Component {
	componentDidMount() {
		var es = new EventSource('http://localhost:8080/sse')
		es.addEventListener('server-time', function (e) {
			console.log(e.data)
		})
	}
	render() {
		return (
			<View/>
		);
	}
}

then there was below error.

error: bundling failed: Error: Unable to resolve module urlfromnode_modules\eventsource\lib\eventsource.js: url could not be found within the project.

I also tried using compiled polyfill or compiling with browserify but another error appeared:

1

Possible Solution
the error when I use your module (not the polyfill) & errors after that was solved after I installed 'url' & other modules like 'http' & 'https' .

then in the bundler I saw below error just as I expected since react-native don't support node core modules due to difference between binary files.

error: bundling failed: Error: While trying to resolve module httpsfrom file\node_modules\eventsource\lib\eventsource.js, the package \node_modules\https\package.jsonwas successfully found. However, this package itself specifies amain module field that could not be resolved (\node_modules\https\index.js)

In the link below I found a way to compile required http, https, base64-js, buffer, ieee754 modules that are available in the node core modules.

After that the http module compiled file with browserify required a file named './decode' and some other files that I couldn't found.

To Reproduce

Just build a react-native project & copy the code into it.

@ghasemikasra39
Copy link

Same here

@aslakhellesoy
Copy link
Contributor

I don't have much time to maintain this library, and I am completely unfamiliar with react-native.

If somebody submits a pull request with a fix I'll consider handing out commit and release access so they can fix and release this themselves.

@aliassarpro
Copy link
Author

Thanks for fast respond aslak. Since I'm working on another project that takes much time from me, I can't help you on that but I hope you leave this issue open to let someone refer & submit a pull request. You can use tags like ( help needed & ... ) too.

@rexxars
Copy link
Member

rexxars commented Dec 7, 2024

I'm curious if the new version (eventsource@^3) works in React Native. It does depend on quite a few "modern" APIs that may or may not exist there. Would love to hear back from someone who can give it a try!

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

4 participants