How to use packages installed with npm in mix?
I wonder how I can use a package installed with NPM in mix?
I have run npm install jquery-validation
Then in my bootstrap.js file I have added: require('jquery-validation');
and in app.js: require('./bootstrap');
My mix file:
mix.js('resources/assets/js/app.js', 'public/js') .extract(['lodash', 'vue', 'axios', 'jquery-validation']); mix.sass('resources/assets/sass/app.scss', 'public/css'); mix.scripts([ 'resources/assets/js/libs/vals.js', 'resources/assets/js/libs/rules.js' ], 'public/js/libs.js');
But I get the error: Uncaught TypeError: Cannot read property 'addMethod' of undefined in libs.js
this is the code:
$(document).ready(function() { $.validator.addMethod("nowhitespace", function(value, element) { return this.optional(element) || /^\S+$/i.test(value); }, "No white space please"); });
But why is addMethod undefined when I have added require('jquery-validation'); in my bootstrap.js file?
Also since I am using jquerys cdn I have removed in from my bootstrap.js and webpack config:
new webpack.ProvidePlugin(Mix.autoload || { //jQuery: 'jquery', //$: 'jquery', //jquery: 'jquery' }),
Please or to participate in this conversation.