#Angular SSE ReferenceError: EventSource is not defined

16 messages · Page 1 of 1 (latest)

flint ermine
#

Hello,
I am trying to make an SSE (Server Sent Event) from my Python script to my Angular 16 application. In the attachments there is a screenshot of my code and the error message. The Error message appears when i open localhost on the browser.

autumn fox
#

Given the stack trace, I guess you enabled SSR on this application, and you're executing this code on the server. I don't think it makes much sense to do that on the server. And apparently, node doesn't support it anyway.
Besides, calling getData() from the constructor on the service and not subscribing to the observable it returns doesn't seem correct either.

flint ermine
#

I havent enabled SSR (server-side rendering) this is basically a new generated angular project

#

I start it with npm start from my pc

#

I have also done this. But it doesnt help to get rid of the error

autumn fox
#

Show us the content of your angular.json file. Or tell us what you find under the distdirectory when executing ng build.

flint ermine
autumn fox
#

See:

            "server": "src/main.server.ts",
            "prerender": true,
            "ssr": {
              "entry": "server.ts"
            }

and the fact that you have a server directory under dist mean that you have enabled ssr in your project.

flint ermine
#

Didn't know i have ssr by default. removing

"ssr": { "entry": "server.ts" }

did the trick, thanks

#

Accually no, it just poped up again 😦

flint ermine
#

I have done some research and Angular 17 has SSR by default. What do you recommend for a communicartion between my python script and my angular 17?

#

Websockets?

autumn fox
# flint ermine I have done some research and Angular 17 has SSR by default. What do you recomme...

No, it doesn't. It asks you whether you want to enable SSR or not, and the default answer is No:

Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? (y/N)
To communicate between a web client and a server, the usual solution is to use HTTP. Use websocket if you need bidirectional full-duplex communication, but that's usually not the case. I'm not sure what this question has to do with SSR though.

flint ermine
autumn fox
#

Re-run ng new for another project, and pay attention to the question it asks. What I pasted is one of the questions it asks.