Require ('jquery') is not defined using elixir / Gulp

I am using an elixir and I cannot work with JS using jQuery. I keep getting this:

var jQuery = require('jquery'); //Uncaught ReferenceError: require is not defined

Here is my elixir function:

elixir(function(mix) {
    mix.sass('app.scss');
    mix.copy('node_modules/font-awesome/fonts', 'public/fonts');
    mix.copy('node_modules/bootstrap-sass/assets/fonts', 'public/fonts');
    mix.copy(['node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
                'node_modules/jquery/dist/jquery.js',
                'node_modules/jquery-ui/jquery-ui.js',
                'node_modules/fullcalendar/node_modules/moment/moment.js',
                'node_modules/fullcalendar/dist/fullcalendar.js',
                'node_modules/fullcalendar/dist/gcal.js',
                'node_modules/dropzone/dist/dropzone.js',
                'node_modules/jquery-datetimepicker/jquery.datetimepicker.js'
            ], 'resources/assets/js/vendors');
    mix.copy('resources/assets/js/vendors/jquery.js', 'public/js');
    // mix.copy('resources/assets/js/vendors/jquery-ui.js', 'public/js');
    // mix.copy('resources/assets/js/vendors/bootstrap.js', 'public/js');
    mix.scripts(['vendors/jquery-ui.js',
                'vendors/bootstrap.js',
                'vendors/contentflow.js',
                'vendors/qTip/jquery.qtip.min.js',
                'vendors/moment.js',
                'vendors/fullcalendar.js',
                'vendors/dropzone.js',
                'vendors/jquery.datetimepicker.js'
            ], 'public/js/vendors.js');
    mix.scripts(['date-time-pickers.js',
                'main.js',
                'search-page.js',
                'social.js',
                'booking-picker.js'
            ], 'public/js/app.js');
});

Any idea what is going on? I tried

mix.browsesify

but he will return

[Laravel Elixir] Browserify Failed!: Cannot find module 'moment'``

Thank you for your help!

+4
source share
1 answer

The warning seems to Uncaught ReferenceError: require is not definedbe what the IDE says because it does not understand how these scripts work together. (I get this warning when working with javascript in Laravel Elixir).

moment. , (). (npm install --save moment) node_modules npm install.

https://momentjs.com/ . , npm.

. , . , npm/Laravel Elixir . , . , package.json , , npm. .

0
source

Source: https://habr.com/ru/post/1608737/


All Articles