Skip to content

jQuery error: $ is not defined / Can't find variable: $ even using legacy workaround #956

Closed
@nicohery

Description

@nicohery

After upgrading to Symfony 5.2.6 (and applying the updated recipes), I "again" encountered the issue in javascript console.

$ is not defined
Can't find variable: $

Same as issue #32 but reappearing after updates.

Our code needs access to $ or jQuery variables outside of JavaScript files processed by Webpack.
I verified my webpack.config.js and my app.js folowing instructions found in Symfony Doc jQuery Plugins and Legacy Applications :

// require jQuery normally
const $ = require('jquery');

// create global $ and jQuery variables
global.$ = global.jQuery = $; 

This workaround doesn’t work and I still have the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions