Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
Webpack Encore + Symfony - Use modules loaded from base

I am miggrating an old big symfony web app to webpack encore. For now, I installed all js libraries, but I found a problem: Uncaught ReferenceError: xxx is not defined

My structure is the next.

  • common.js where I import js libraries that I was used in a lot of pages (like resize-sensor).
  • base.html.twig where I call {{ encore_entry_script_tags('common') }}
  • Final views which extends base.html.twig

In common.js I load librarys: Ej. import 'resize-sensor';

In a view I try to use: new ResizeSensor(jQuery('#div-left'), function(){fixElements();});

I got this error: "Uncaught ReferenceError: ResizeSensor is not defined"

I had to import jquery, highcharts and confirmation2 globally, but I am not sure that i want to do this with all libraries.

So is there any way to import all content from common in all views which extends from base?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In a view I try to use: new ResizeSensor(jQuery('#div-left'), function(){fixElements();});

Importing libs in your js-files, doesn't make then "available" in global scope. So you can't just use them in your views like

{% block javascripts %}
   {{ parent() }}
   <script>
     $(function(){
        new ResizeSensor(jQuery('#div-left'), function(){fixElements();});
     });
   </script>
{% endblock %}

They are actually available only in that file (common.js)

You could try to use special global. syntax OR you try to make them as autoProvidedVariables. You have to play around which works best for you

global

// in your common.js

import ResizeSensor from 'resize-sensor';

global.ResizeSensor = ResizeSensor; // now is ResizeSensor available globaly

autoProvideVariables

// in webpack.config.js

.autoProvidejQuery()
.autoProvideVariables({
   ResizeSensor:  require.resolve('resize-sensor'),
}

now you could use them in your views.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!