EventSource
EventSource copied to clipboard
How to use with last version of React.js
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.htmllike any other "old school" scripts: "TS2304: Cannot find name 'EventSourcePolyfill'." - Import it in the
public/index.htmllike any other "old school" scripts AND declare it as for angular by usingdeclare var EventSourcePolyfill: any;: Uncaught SyntaxError: Unexpected token '<' (the < symbol is actually the beginning of the <!Doctype> tag of thepublic/index.htmlpage - 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?
You can import like this import {EventSourcePolyfill} from "event-source-polyfill";
Full Code