Hello,
I am working on a Magento 2 site and for this site I need a certain shipment provider module. Whenever I install this module, none of the .js files and JQuery like the slider etc. are not displaying anymore. The browser developer tools are full of;
Uncaught TypeError: $(...).swMegamenu is not a function
Uncaught TypeError: $(...).owlCarousel is not a function
Uncaught TypeError: $(...).stellar is not a function
Uncaught TypeError: $(...).owlCarousel is not a function
And in the exception log I see this;
Unable to get content for 'frontend/Smartwave/porto_child/en_US/Module_Name/js/module-file.js' {"exception":"[object] (Magento\\Framework\\View\\Asset\\File\\NotFoundException(code: 0): Unable to get content for 'frontend/Smartwave/porto_child/en_US/Module_Name/module-file.js' at /home/yczswebh/public_html/vendor/magento/framework/View/Asset/File.php:186)"} []
The module developer has not been super helpful so far so I was hoping one of you may have a solution to my problem.
Solved! Go to Solution.
Hello @m_w1,
create a requirejs-config.js in the root of the child theme
app/design/frontend/Smartwave/porto_child and put in the following:
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 change the entries:
<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" />
Within file:
app/design/frontend/Smartwave/porto_child/Magento_Theme/layout/default_head_blocks.xml
No more need for merging javascripts, no more javascript errors! I have no need for the fancybox, turned it off, but if you do require it, I guess it should be included in the requirejs as well.
Let us know if you get trouble with it.
--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"
Hello @m_w1,
create a requirejs-config.js in the root of the child theme
app/design/frontend/Smartwave/porto_child and put in the following:
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 change the entries:
<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" />
Within file:
app/design/frontend/Smartwave/porto_child/Magento_Theme/layout/default_head_blocks.xml
No more need for merging javascripts, no more javascript errors! I have no need for the fancybox, turned it off, but if you do require it, I guess it should be included in the requirejs as well.
Let us know if you get trouble with it.
--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"
Hello @gelanivishal
Thank you for your reply.
I have tried this before but I don't have the directory Magento_Theme in app/design/frontend/Smartwave/porto_child/
Please create this as per directory
app/design/frontend/Smartwave/porto_child/Magento_Theme/layout/default_head_blocks.xml
and add below content in it.
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <head> <remove src="jquery.js" /> <remove src="bootstrap/js/bootstrap.min.js" /> <remove src="fancybox/js/jquery.fancybox.js" /> </head> </page>
Kindly refer below blogs for resoled your jquery error,
You need to run deployment command after set jquery in requirejs-config.js file.
Hello @Rakesh Jesadiya
Thank you for your suggestion!
This is very new to me and I would appreciate a bit of clarification if possible.
One of the errors is 'Uncaught TypeError: $(...).swMegamenu is not a function' which I found the file sw_megamenu.js in app/code/Smartwave/Megamenu/view/frontend/web/js
I have followed your steps and now have a requirejs-config.js file in my theme directory.
app/design/frontend/Smartwave/porto_child
The file looks like this
var config = {
paths: {
'swMegamenu': 'Smartwave_Megamenu/js/sw_megamenu.js'
},
shim: {
'swMegamenu': {
deps: ['jquery'] //gives your parent dependencies name here
}
}
};
I have deployed content again and cleared cache but it still gives errors, did I do something wrong?
You need to create requirejs-config.js file at below location.
app/code/Smartwave/Megamenu/view/frontend/requirejs-config.js