question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERROR ReferenceError: $ is not defined (on the server console)

See original GitHub issue

Bug 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:closed
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
ohabashcommented, Jan 29, 2019

Don’t do any ssr on Frontend scripts

3reactions
andresmgslcommented, Sep 30, 2018

+1 … I also experimenting that error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught ReferenceError: $ is not defined? - Stack Overflow
The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library file...
Read more >
ReferenceError: "x" is not defined - JavaScript - MDN Web Docs
ReferenceError : "x" is not defined. The JavaScript exception "variable is not defined" occurs when there is a non-existent variable referenced somewhere.
Read more >
3 Ways to Solve jQuery - Uncaught ReferenceError: $ is not ...
1) One of the most common reason of "ReferenceError: $ is not defined" in jQuery based application is that jQuery plugin is included...
Read more >
Uncaught ReferenceError: $ is not defined
Basically $ is an alias of jQuery() so when you try to call/access it before declaring the function, it will endup throwing this...
Read more >
How to Fix ReferenceError: Event is Not Defined in JavaScript
The Javascript ReferenceError is thrown when an attempt is made to reference a non-existing or out of scope variable. Not defining a variable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found