コミュニティアチーブメントバーを展開する。

Submissions are now open for the 2026 Adobe Experience Maker Awards.
解決済み

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 受け入れられたソリューション

Avatar

正解者
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

元の投稿で解決策を見る

16 返信

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 please find the reference here

https://experience-aem.blogspot.com/2020/01/aem-6530-core-components-280-touch-ui-rte-rich-text-edit...

Avatar

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

Avatar

Community Advisor

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

正解者
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

Community Advisor

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

AEM LinksLinkedIn

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

Level 2

Thanks @nibedita07 It worked

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

Avatar

Level 1

This worked for me thank you