1

I'm working on a project using Vue 3. I tried to add bootstrap-material-datetimepicker into my project. This is how I import it on my Vue component file.

<template>
    <div>
        <!-- -->
    </div>
</template>

<script>
// ..

import 'bootstrap-material-datetimepicker/js/bootstrap-material-datetimepicker.js'
import 'bootstrap-material-datetimepicker/css/bootstrap-material-datetimepicker.css'

// ..
</script>

I get an error when trying to run that. From the error, I can tell that somehow jquery is not detected on my app. It's weird since I believe I've added the jquery plugin definition into vue.config.js file.

const webpack = require('webpack')

module.exports = {
    baseUrl: '/public/',
    plugins: [
        new webpack.ProvidePlugin({
            $: 'jquery',
            jquery: 'jquery',
            'window.jQuery': 'jquery',
            jQuery: 'jquery'
        })
    ]
}

On the browser console below is the error that I get:

vue-router.esm.js?8c4f:1905 ReferenceError: jQuery is not defined at eval (bootstrap-material-datetimepicker.js?5260:1295) at Object../node_modules/bootstrap-material-datetimepicker/js/bootstrap-material-datetimepicker.js (vendors~PublicSignUp.js:76) at webpack_require (app.js:768) at fn (app.js:131) at eval (cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/pages/public/SignUp.vue?vue&type=script&lang=js&:6) at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/pages/public/SignUp.vue?vue&type=script&lang=js& (PublicSignUp.js:11) at webpack_require (app.js:768) at fn (app.js:131) at eval (SignUp.vue?8585:1) at Module../src/pages/public/SignUp.vue?vue&type=script&lang=js& (PublicSignUp.js:80)

What should I do to resolve this issue?

1 Answer 1

2

Just saw similar issue on github, turns out I just need to wrap the plugins inside configureWebpack.

const webpack = require('webpack');

module.exports = {
    baseUrl: '/public/',
    configureWebpack: {
        plugins: [
            new webpack.ProvidePlugin({
                '$': 'jquery',
                'jquery': 'jquery',
                'jQuery': 'jquery',
                'window.jQuery': 'jquery',
                'moment': 'moment'
            })
        ]
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.