S
S
Stanislav Shendakov2021-03-30 05:01:13
symfony
Stanislav Shendakov, 2021-03-30 05:01:13

How to include jquery in symfony 5?

Good afternoon.

There was already such a question, but no one has answered yet. Symfony 5 and the same problem, jQuery is not included.
In assets/app.js:

...
const $ = require('jquery');
global.$ = global.jQuery = $;
...

In webpack.config.js:
...
    // uncomment if you're having problems with a jQuery plugin
    .autoProvidejQuery()
...

I run yarn encore dev --watch and everything compiles without errors. In the template I write:
...
<script>
console.log( $ )
</script>

I get Uncaught ReferenceError: $ is not defined. If jquery.min.js is included in the template itself via , everything works, but I would like to do everything ideologically correct, via Encore. Documentation read both translated and original. What did I miss? Thank you. <script src="...">...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question