I'm using laravel-5
that comes with webpack
and laravel-mix
, the idea is to use the library datetimepicker
that at the same time uses momentjs
. The problem is that I can not include the library in any way.
I have tried everything I could read, but only one thing has made me move forward:
First
npm install datetimepicker --save-dev
npm install moment --save-dev
Then one of these two:
Make a require('../../../node_modules/moment/min/moment-with-locales.js');
in resources/assets/js/app.js
Or edit webpack.mix.js
:
mix.js([
//Plugins
'node_modules/moment/min/moment-with-locales.js',
'node_modules/admin-lte/plugins/daterangepicker/daterangepicker.js',
], 'public/js/app.js');
After both cases, npm run dev
or npm watch
is executed, before finishing, I always get the following error:
WARNING in ./~/moment/min/moment.min.js
Module not found: Error: Can't resolve './locale' in '/proyecto/node_modules/moment/min'
@ ./~/moment/min/moment.min.js 6:16637-16659
I have been able to read a lot about the subject, and I have only found one way in which the error does not appear, they say it here. .
Even so, compiling well and without giving any error, when I try to execute console.log(moment().millisecond());
I always get the error in console: ReferenceError: moment is not defined
Comment on the own page of momentjs
use var moment = require(...)
, which also they mention it in the issue
of github
, but nothing, the same.
Does anyone who uses datetimepicker
or failing momentjs
with Laravel5
know how to include the library without errors?
My resources/assets/js/app.js
file:
require('./bootstrap');
//var moment = require('moment');
require('../../../node_modules/moment/min/moment-with-locales.js');
console.log(moment().millisecond());
require('../../../node_modules/admin-lte/plugins/daterangepicker/daterangepicker.js');