Javascript File not working in symfony twig

In my symfony project my css is well linked, but my javascript is not working and I can’t find why. I guess something stupid I missed …! I tried with the encore webpack at firt since I’m runninh Sass, but I gave up and switched to the classi src=""

<!DOCTYPE html>
        <meta charset="UTF-8">
        <title>{% block title %}Welcome!{% endblock %}</title>
        {# Run `composer require symfony/webpack-encore-bundle`
           and uncomment the following Encore helpers to start using Symfony UX #}
        {% block stylesheets %}
{#            {{ encore_entry_link_tags('app') }}#}
{#            {{ encore_entry_script_tags('app') }}#}
           <link rel="stylesheet" href="{{ asset('bundles/mercuryseriesflashy/css/flashy.css') }}">
            <link rel="stylesheet" href="{{ asset('./build/app.css') }}">
        {% endblock %}

        {% block javascripts %}
{#            {{ encore_entry_script_tags('app') }}#}
            <!-- Flashy depends on jQuery -->

        {% endblock %}
    {% block navbar %} {% include 'inc/navbar.html.twig'%}{% endblock %}
        {% block body %}{% endblock %}
        {% block footer %}{% endblock %}
    <script src="{{ asset('./build/app.js') }}"></script>

    <script src="//"></script>


 * Welcome to your app's main JavaScript file!
 * We recommend including the built version of this JavaScript file
 * (and its CSS file) in your base layout (base.html.twig).

// any CSS you import will output into a single css file (app.scss in this case)
import './styles/app.scss';

import './bootstrap';
// start the Stimulus application

const logoMenu = document.querySelector('.logoMenuImg');
const contItems = document.querySelector('.contItems');
const arrItems = document.querySelectorAll('.items');



alert('hello world');

Thank you for your help

p.s: in the inspector it’s blank no erros

1 thought on “Javascript File not working in symfony twig”

  1. If you are using encore_entry_script_tags i assume you have add your JS file in your webpack configuration ?
    I see you’re using assetic, if you are in Symfony 4.4 and more, remove it, it’s deprecated. Use Webpack encore.

    let Encore = require('@symfony/webpack-encore');
    let CopyWebpackPlugin = require('copy-webpack-plugin');
    //let TerserPlugin = require('terser-webpack-plugin');
      // directory where compiled assets will be stored
      // public path used by the web server to access the output path
      .addEntry('app', './assets/js/app.js')
    module.exports = Encore.getWebpackConfig();

    And run with npm run build or yarn encore <env>
    Look at documentation:


Leave a Comment