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>
Mujahidh
2,7825 gold badges41 silver badges87 bronze badges
asked Jan 5, 2016 at 7:01

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.

answered Jan 5, 2016 at 7:10
3
  • thanks marius this is helped me lot...but i am not understanding that what wrong with requirejs-config.js file Commented Jan 5, 2016 at 7:17
  • Me neither. If I find something I will post it here. Commented 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? Commented 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.

answered Jan 5, 2016 at 7:04
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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.