7

I followed this tutorial to create a chat app with and .

I get require is not defined error in app.js:8.I tried so many things but but nothing seems to solve this problem.

I tried using requirejs so i added these two line in my view

<script type="text/javascript" data-main="{{ url('resources/assets/js/app.js')}}" src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
<script src="{{ url('resources/assets/js/app.js')}}"></script>

and this is my app.js code:

requirejs.config({
baseUrl: 'js/lib',
paths: {
    app: '../app'
}
});

requirejs(['jquery', 'canvas', 'app/sub'],
 function   ($,        canvas,   sub) {
});
// this line below is causing the problem
require('./bootstrap');

window.Vue = require('vue');
Vue.use(require('vue-chat-scroll'));

Vue.component('chat-message', require('./components/ChatMessage.vue'));
Vue.component('chat-log', require('./components/ChatLog.vue'));
Vue.component('user-log', require('./components/UserLog.vue'));
Vue.component('chat-composer', require('./components/ChatComposer.vue'));
Youssef Boudaya
  • 123
  • 1
  • 2
  • 15
  • 1
    Welcome to Stackoverflow, please post a minimal version of your code as we are not magicians and have absolotely no clue of what is on line 8. – Borjante Dec 07 '18 at 09:55
  • Read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Decade Moon Dec 07 '18 at 09:58
  • i just updated my question to include the line that causing the error – Youssef Boudaya Dec 07 '18 at 10:11

2 Answers2

5

You shouldn't be referencing resources/assets/js/app.js directly. require is used by webpack which is a tool that will bundle your js assets into a single file.

Instead you should run npm run development and then reference js/app.js like here

See laravel mix docs

noj
  • 6,740
  • 1
  • 25
  • 30
0

You may have to add this to your project : https://requirejs.org/docs/release/2.3.5/minified/require.js

There is a similar issue for your problem right there : Javascript require() function giving ReferenceError: require is not defined

hbled
  • 1
  • 3
  • i just updated my question to show the code of my app.js where the error is how should i change that file when now working with requirejs ? – Youssef Boudaya Dec 07 '18 at 10:11