Expand my Community achievements bar.

SOLVED

Uncaught ReferenceError: _ is not defined

Avatar

Community Advisor

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
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

View solution in original post

16 Replies

Avatar

Community Advisor

Hi @sravs 

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

 

Thanks!

Avatar

Community Advisor
I have tried that as well, but its not working

Avatar

Community Advisor
What type of custom clientlib it is? Is it reproducible on we-retail as well?

Avatar

Community Advisor
Yeah, I'm using AEM 6.5.3 I tried to add a colorpicker plugin for RTE

Avatar

Community Advisor
@asutosh Tried underscore as well but no luck

Avatar

Community Advisor

@sravs If this is still not resolved, please share the code package to debug further.

Avatar

Correct answer by
Community Advisor
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

Avatar

Level 1

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)

 

Avatar

Level 1

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

Avatar

Level 2

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

nibedita07_0-1669045007076.png

 

Avatar

Administrator

@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