简体   繁体   中英

Laravel 5.8 require function in app.js not found

I'm trying to add a chart in my Laravel frontend application.

  1. In app.js I added require('./horizBarChart');
  2. In app.scss I added @import 'horizBarChart.scss';
  3. After app.js I added the function call method (and a jQuery test, that works): 在此处输入图片说明

Now, after compiling I see that the horizBarChart function is included in my app.js generated file: 在此处输入图片说明

But when opening the website I still get funtion not found error: 在此处输入图片说明

If I dont use require but include it as basic <script src="../jquery.horizBarChart.min.js"></script> all works fine.

What am I doing wrong here?

link tag in HTML is used for css, for scripts it should be:

<script src="/js/app.js"></script>

And also I think you should put this line below jQuery, not above as I see the library also uses jQuery, so make sure that jQuery is loaded first.

JS file "app.js" You've included in Style/CSS/Link Tag, You need to include in Script Tag:

check here

For Javascript:

<script type="text/javascript" src="{{ URL::asset('js/app.js') }}"></script>

Make your directory structure is like this for JS: /public/js/app.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM