I’m using Smartwave Porto theme for my Magento 2 website. When I load my website for the first time it’s loading properly, but every time I refresh the browser page it will show an error like this in browser console and my page does not load properly:
Uncaught TypeError: $(...).swMegamenu is not a function Uncaught TypeError: $(...).stellar is not a function Uncaught TypeError: $(...).owlCarousel is not a function Uncaught TypeError: $.widget is not a function
I just do below changes :
Create a requirejs-config.js in the root of the child theme (you can also do this on root theme if you have not created a child theme) as per Porto child like this:
app/design/frontend/Smartwave/porto_child and add the following code in it:
var config = {
shim: {
jquery: {
exports: '$'
},
'Smartwave_Megamenu/js/sw_megamenu':
{
deps: ['jquery']
},
'owl.carousel/owl.carousel.min':
{
deps: ['jquery']
},
'js/jquery.stellar.min':
{
deps: ['jquery']
},
'js/jquery.parallax.min':
{
deps: ['jquery']
}
}
};
And also change child theme layout file at:
app/design/frontend/Smartwave/porto_child/Magento_Theme/layout/default_head_blocks.xml
From:
<script src="jquery.js" /> <script src="bootstrap/js/bootstrap.min.js" /> <script src="fancybox/js/jquery.fancybox.js" />
To:
<remove src="jquery.js" /> <remove src="bootstrap/js/bootstrap.min.js" /> <remove src="fancybox/js/jquery.fancybox.js" />
I don’t need the fancybox, So I have turned it off, but if you require it, I guess it should be included in the requirejs as well. If you face the same issue, follow the above steps to solve it.

