EventSource icon indicating copy to clipboard operation
EventSource copied to clipboard

How to use with last version of React.js

Open geoffroyp opened this issue 3 years ago • 2 comments

Hi guys,

I'm trying since way too long to import this library in a React project using React's last version. At the moment, it's just a sandbox to try various things.

But I miserably fail everytime. I have tried to:

  • Import it in the public/index.html like any other "old school" scripts: "TS2304: Cannot find name 'EventSourcePolyfill'."
  • Import it in the public/index.html like any other "old school" scripts AND declare it as for angular by using declare var EventSourcePolyfill: any; : Uncaught SyntaxError: Unexpected token '<' (the < symbol is actually the beginning of the <!Doctype> tag of the public/index.html page
  • Import it like a module: import * as ES from "../node_modules/event-source-polyfill/src/eventsource.min.js"; -> nope: Could not find a declaration file for module '../node_modules/event-source-polyfill/src/eventsource.min.js'
  • Import it like a module: import EventSourcePolyfill from "../node_modules/event-source-polyfill/src/eventsource.min.js"; -> nope, same error
  • Import it like a module: import EventSourcePolyfill from "../node_modules/event-source-polyfill/src/eventsource.min.js"; -> nope, Could not find a declaration file for module 'event-source-polyfill'.

etc, etc...

I'm new to react, so i'm probably doing something wrong, but I hardly understand why we couldn't import it like any other module with a simple import EventSourcePolyfill from "event-source-polyfill";

Any idea / savior?

geoffroyp avatar Mar 28 '22 08:03 geoffroyp

You can import like this import {EventSourcePolyfill} from "event-source-polyfill"; Full Code

sbx0 avatar Apr 01 '22 08:04 sbx0