Run javascript function using symfony form and twig

I’m trying to execute a function when the user press a key on a form input. To do so, I’m using Symfony with Twig and webpack. Now, when I pass the attribute onkeydown to call the function test(), in the browser I always get the error:

Uncaught ReferenceError: test is not defined onkeydown http://localhost/register:1

Here’s an excerpt of the code

My form: RegistrationFormType.php

public function buildForm(FormBuilderInterface $builder, array $options): void
{
    $builder
        ->add('username', TextType::class, [
            'attr' => ['onkeydown' => 'test()']
        ])
}

My js test file:

function test(){
    console.log("test");
}

App.js:

import './bootstrap.js';
import './styles/new-account.css';
import './controllers/test.js'

On my browser:
enter image description here