0

I created one module and i want to add js file to that module but in DOM i am getting "404 not found" my file are
My\Helloworld\view\frontend\requirejs-config.js

var config = {
    map: {
        '*': {
            test1: 'My_Helloworld/js/test1'
        }
    },
};

My\Helloworld\view\frontend\web\js\test1.js

define([
    "jquery"
], function($) {
    "use strict";
    $(document).ready(function(){
        alert('Test JS');
    });
});

My\Helloworld\view\frontend\templates\helloworld.phtml

<script type="text/javascript">
    require(['jquery','test1'],function($){
        $(window).load(function() {
            $('.flexslider-8').flexslider({
                animation: "fade",
                controlNav: "thumbnails",
                slideshowSpeed: 2000,
                minItems: 2,
                maxItems: 4
            });
        });
    });
</script>

3 Answers 3

2

Instead of require(['jquery','test1'],function($){... try it with this:

require(['jquery','My_Helloworld/js/test1'],function($){ ...

This way you won't need the requirejs-config.js file.

3
  • thanks marius this is helped me lot...but i am not understanding that what wrong with requirejs-config.js file Jan 5, 2016 at 7:17
  • Me neither. If I find something I will post it here.
    – Marius
    Jan 5, 2016 at 7:17
  • requirejs-config.js:: in my case it is somehow missing "/js/" part in the url, which is why it's throwing 404. Any idea? Dec 20, 2017 at 9:01
0

you can get it in any .phtml file by path

<link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('Package_Module::css/flexslider.css')?>">

I hope this will help you.

0

Please compare your try with How to load custom module js file in magento 2?. still you get same error then please comment here. You can implement use shim to maintain jQuery dependency.

1
  • i followed this one only but unfortunately i was getting 404 error but marius answer solved this 404 not found error. Jan 5, 2016 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.