Uncaught ReferenceError: CQ is not defined | Community
Skip to main content
Level 2
Dec 6, 2017 7:15 AM UTC

Uncaught ReferenceError: CQ is not defined

Hi there,

I am upgraded from AEM 6.0 to  AEM 6.2. There was some changes required and I have done those. Everything was fine. Recently I have upgraded CFP8. After that I am getting Uncaught ReferenceError: CQ is not defined in browser console in every page. I am getting this error in both author and publish instance. Here is the QA publish server of my application: Cheap Rental Cars and Car Rental Deals Worldwide - Fox Rent A Car.​

Can you please help me to resolve this issue?

Here is my current instance version:

Adobe Experience Manager, Version 6.2.0.SP1-CFP8

Here is the browser console error:

Uncaught ReferenceError: CQ is not defined

     at main.js:97

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

20 replies

May 30, 2019 8:52 AM UTC

Hi,

I got the solution of the issue, just change the use js name and its reference, like in my case js name was caseStudy.js so I changed it to caseStudyJS.js and also its reference and it worked.

Translate
brianw48577253
New Participant
Oct 30, 2019 6:22 PM UTC

gauravm29742313 ' s solution worked for me, but I almost skipped over it because I didn't understand.

Make sure your js file does not match the same of the component folder it sits in.

for example, I changed:
.../blank-page/blank-page.js

to

.../blank-page/blankPage.js

Translate
Bharath_valse
Level 4
Jul 17, 2018 9:08 PM UTC

To fix this, you can add cq.shared dependency on "/etc/clientlibs/foundation/main" and it will work fine

Translate
suhashankare
New Participant
Aug 6, 2018 1:40 PM UTC

This Solution worked on, 6.4 instance, however this issues was with dispatcher which is resolve now, but at the first shot adding dependencies 'CQ.Shared ' worked for me on 6.4 Instance

Translate
New Participant
Dec 27, 2018 9:44 AM UTC

Can you please give your inputs on this issue. this is issue got when using below code as page component.I am getting below " "use" is not defined" error during the AEM upgrade from 6.2 to 6.4.

--> <div data-sly-use.data="company-linkpage.js" id="company-links"> This is the div using the  .js file 

Below is the Complete Error:

--------------------------------------

ReferenceError: "use" is not defined       

Cannot serve request to /content/project/en/content/Tools_and_Resources.html in /apps/project/company-linkpage.js

Exception: <eval>:3 ReferenceError: "use" is not defined  at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)  at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)  at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)  at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1441)  at jdk.nashorn.internal.scripts.Script$\^eval\_.:program(<eval>:3)  at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637)  at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)  at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)  at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:421)  at jdk.nashorn.api.scripting.NashornScriptEngine.access$300(NashornScriptEngine.java:73)  at jdk.nashorn.api.scripting.NashornScriptEngine$3.eval(NashornScriptEngine.java:514)  at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:386)    at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:184)    at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:4 91)  at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:552)  at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponen

----------------------------------------------------------------------------------------- --------

Below is the code for company-linkpage.js :

"use strict";

use(['/apps/project/components/structure/basepage/userProfile.js'], function (userProfile) {

    var ret = {

        image: null,

        favoriteUrl: currentPage.path + '.html',

        userCanEdit: false,

        userCanEditTeam: false,

        isAnonymous: userProfile.isAnonymous()

    },

        image = currentNode.hasNode('image') ? currentNode.getNode('image') : null;

    ret.isFavorite = userProfile.isFavorite(ret.favoriteUrl);

    if (image) {

        ret.image = image.hasProperty('fileReference') ? image.getProperty('fileReference') : null;

    }

    if (!ret.image) {

        try {

            var res = image.hasNode("file") ? image.getNode("file") : null;

            ret.image = res.getPath();

            ret.image = "background-image: url("+ ret.image + ");";

        } catch(err) {

            ret.image = "background-image: url(http://placehold.it/150x150?text=Placeholder);";

        }

    } else {

        ret.image = "background-image: url(" + ret.image + ");";

    }

    var roles = userProfile.getRoles().iterator();

    while (roles.hasNext()) {

        var role = roles.next();

        if (role.label.equalsIgnoreCase('Non-Sales Leaders')) {

            ret.userCanEdit = 'true';

        } else if (role.label.equalsIgnoreCase('Non-Sales Editor')) {

            ret.userCanEdit = 'true';

        } else if (role.label.equalsIgnoreCase('Team Leader')) {

            ret.userCanEditTeam = 'true';

        }

    }

    ret.isAnonymous = userProfile.isAnonymous();

    return ret;

});  

Translate
smacdonald2008
Level 10
Dec 6, 2017 10:06 PM UTC

I ahve checked with internal ppl to see if this is a known issue.

Translate
smacdonald2008
Level 10
Dec 6, 2017 10:08 PM UTC

By the way - nice site. If you ever want to contribute some community code that help the AEM DEV community - let us know.

Translate
maherajAuthor
Level 2
Dec 7, 2017 4:32 AM UTC

I need to resolve this issue. This issue is blocking my next release. If you can help me on this it will be great. Thank you.

Yes, I shall be glad to contribute some community code. Thank for the complement.

Translate
Employee
Dec 6, 2017 8:50 AM UTC

Make sure cq.widgets is added as dependency in your client lib.

dependenciesString[]cq.widgets
Translate
maherajAuthor
Level 2
Dec 6, 2017 9:19 AM UTC

This is the path of my client libs folder this my my client lib folder: /etc/designs/dotcom/clientlibs_base . And I have added the dependencies. Still issue is there.

Translate
Employee
Dec 6, 2017 5:33 PM UTC

Error is reported from main.js (loaded on top of the page)

And clientlibs_base.js is loaded at the end of the page. You might need to look into ordering of the client libraries in which they are included in the page.

Translate