Uncaught ReferenceError: _ is not defined | Community
Skip to main content
sravs
Community Advisor
Community Advisor
March 26, 2021
Solved

Uncaught ReferenceError: _ is not defined

  • March 26, 2021
  • 6 replies
  • 35779 views

while I'm trying to use a custom clientlib its throwing the error as Uncaught ReferenceError: _ is not defined I added dependency as lodash also.

can you please help me in this

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Bhuwan_B
Usually this error comes if your code has dependency on Underscore.js/LoDash.js . Can you please try validating if its added and loading properly. https://stackoverflow.com/questions/13556010/referenceerror-is-not-defined

6 replies

Asutosh_Jena_
Community Advisor
Community Advisor
March 26, 2021

Hi @sravs 

Please add 'cq.jquery' as dependency and see if it resolves the issue.

 

Thanks!

sravs
Community Advisor
sravsCommunity AdvisorAuthor
Community Advisor
March 26, 2021
I have tried that as well, but its not working
Bhuwan_B
Community Advisor
Bhuwan_BCommunity AdvisorAccepted solution
Community Advisor
March 28, 2021
Usually this error comes if your code has dependency on Underscore.js/LoDash.js . Can you please try validating if its added and loading properly. https://stackoverflow.com/questions/13556010/referenceerror-is-not-defined
arunpatidar
Community Advisor
Community Advisor
March 28, 2021

please check sample code here if you are using color picker 

https://aemlab.blogspot.com/2019/07/aem-rte-custom-plugins-1.html

Arun Patidar
June 29, 2021

If you are using any script file and getting "Uncaught ReferenceError: x is not defined " which means 'x' is either a variable or a method which you are trying to use before declaring it using var keyword. This means that there is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it is available in your current script or scope otherwise , it will endup throwing this 'x' is not defined error . This usually indicates that your library is not loaded and JavaScript does not recognize the 'x'.

 

To solve this error: Load your library at the beginning of all your scripts.

 

There can be multiple other reasons for this issue:

 

  • Conflict with Other Libraries
  • Path to your library included is not correct
  • Llibrary file is corrupted
  • Working offline (when you use CDN)

 

November 2, 2021

I fixed it by removing the underscore.js dependency altogether. Added equivalent functions that were used from underscore.js

Adobe Employee
November 21, 2022

@sravs  Please use this lodash.underscore as dependencies in the clientlib node if the issue is not resolved yet.

 

March 10, 2023

Thanks @nibeditana It worked

kautuk_sahni
Community Manager
Community Manager
June 7, 2024

@dasiascott99 @bhargav1817 We hope you found the AEM community valuable. We anticipate your return as either a learner or a contributor. The community benefits from SMEs like you. Please ask your AEM peers to join and contribute. Happy AEM learning!

Kautuk Sahni