ERROR ReferenceError: $ is not defined (on the server console)
See original GitHub issueBug Report
My app uses plugins dependent on jQuery. when i start the universal server I see a lot of errors related to jQuery.
ERROR ReferenceError: $ is not defined
What is the expected behavior?
I expected that javascript related to dom elements would be ignored / suppressed or simulated for server side rendering without the need to modify the frontend app extensively
what ive tried
i started to put if(isBrowser)
statements around dom scripts but this broke too many other parts and is not ideal because id basically have to rewrite a big percent of the app.
i started to convert jq to js but that also had problems with undefined elements
Uncaught TypeError: Cannot read property 'classList' of undefined
Uncaught TypeError: Cannot read property 'styles' of undefined
What is the use-case or motivation for changing an existing behavior?
It would really be nice if the app ran without issue on the server as it does in the dom.
Environment:
@nguniversal versions
- common:
^6.0.0
- express-engine:
^6.1.0
- module-map-ngfactory-loader:
^6.1.0
Is there anything else we should know?
I had a similar problem with window
and document
and localStorage
. I found a solution that only required that i modify the server with mock-browser instead of re-writing the frontend app. a solution like that for jquery would be gold. Please help my client will surely fire me without a solution. https://blog.khophi.co/localstorage-undefined-angular-server-side-rendering/
ALSO
Right now when looking at page source i can see that certain components do not render (server-side). could that be a result of ERROR ReferenceError: $ is not defined
?
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (1 by maintainers)
Don’t do any ssr on Frontend scripts
+1 … I also experimenting that error