Jump to content

get Uncaught ReferenceError: $ is not defined console error


Recommended Posts

I'm getting `Uncaught ReferenceError: $ is not defined` error.

I've define my js and css under, hookBackOfficeHeader() using 
$this->context->controller->addJS($this->_path . 'views/js/filename.js');

can anyone help me 

Link to comment
Share on other sites

On 6/4/2021 at 4:51 PM, Crezzur said:

Reset your module then other while your module hook is not registered

Hi 
the error is coming on module manager now :( 

 

    public function hookBackOfficeHeader()
    {
        $this->context->controller->addJquery();
        $this->context->controller->addCSS($this->_path . 'views/css/file.css');
        $this->context->controller->addJS($this->_path . 'views/js/file.js');
        Media::addJsDef([
            'base_url' => $this->context->link->getAdminLink('fileTab'),
        ]);
    }

image.thumb.png.1239fa1895a4479deec038feb6dc1af5.png

Link to comment
Share on other sites

    /*------ Tabs functionality --------*/
    $(document).on('click', '#tabOrder a', function(clicked) {
        clicked.preventDefault()
        clicked.tab('show')
    });

Not sure if the error is here, try to use the code above which works better on dynamically created content.

Link to comment
Share on other sites

2 minutes ago, Crezzur said:

    /*------ Tabs functionality --------*/
    $(document).on('click', '#tabOrder a', function(clicked) {
        clicked.preventDefault()
        clicked.tab('show')
    });

Not sure if the error is here, try to use the code above which works better on dynamically created content.

Didn't worked the error remains. The issue is in `$(document).ready(function () {`

 

Link to comment
Share on other sites

I've removed everything from my JS file now it have only this 

 

$(document).ready(function () {
    
});


The error is coming on the module manager page. 

In console 

image.thumb.png.30ff8b24ef7007a997239a9709b0e00d.png
 

This error is only coming for PS 1.7.6.5 to 1.7.6.9 version.
 

Link to comment
Share on other sites

1 minute ago, Gouravdev said:

I've removed everything from my JS file now it have only this 

 


$(document).ready(function () {
    
});


The error is coming on the module manager page. 

In console 

image.thumb.png.30ff8b24ef7007a997239a9709b0e00d.png
 

This error is only coming for PS 1.7.6.5 to 1.7.6.9 version.
 

Check your page to see if your javascript file is called after jquery and not before.

Link to comment
Share on other sites

Check your page source when your page is loaded. If your java-script is loaded like below its fine

 

<script type="text/javascript" src="/storea/js/jquery/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="/storea/js/jquery/bo-migrate-mute.min.js"></script>
...
<script type="text/javascript" src="/storea/backoffice/yourscript.js"></script>

 

Link to comment
Share on other sites

  • 8 months later...
On 6/7/2021 at 2:12 PM, Gouravdev said:

Uncaught ReferenceError: $ is not defined the error still remains

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)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...