Skip to content

Can't use eventsource javascript package #12890

@mythz

Description

@mythz

The eventsource package is a pure JavaScript implementation of the EventSource client which aims to be W3C compatible and provides a simple solution for real-time notifications over http which is especially useful in mobile apps.

Funnily EventSource works when debugging JS Remotely as it's able to use the built-in EventSource in Chrome, but doesn't work when debugging is disabled as it fails with:

Can't find variable: EventSource

Then trying to import the JavaScript eventsource:

yarn add eventsource 

fails with similar results in npm or yarn when trying to import it:

global.EventSource = require('eventsource');

iOS displays an error page with Unable to resolve module {module_name} from ../node_modules/eventsource/lib/eventsource.js. First it fails with url module, which I then import with:

yarn add url

Then it continues with the same error page for the following core modules used by eventsource:

  • events
  • https
  • http
  • util

Then when all these modules are added if ends up failing with Unable to resolve module https... even though it's already added. This exact failing sequence also happened before I had yarn installed.

Solution

The error is due to failing to load core node.js modules so it looks like it's either a module loading error or react-native doesn't support these core node.js modules. It would help with compatibility of other packages if react-native had built-in support for these core modules.

Additional Information

  • React Native version: latest react-native 0.42.0
  • Platform: iOS
  • Operating System: OSX 10.12.3 (Sierra)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions