Importing bootstrapVue in vue 3
Asked Answered
G

1

9

Hi I was trying to use bootstrapVue in my vue 3 application with typescript here is my main.ts:

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import Vue from 'vue'

import { BootstrapVue } from 'bootstrap-vue'

createApp(App).use(router).use(BootstrapVue).mount('#app')

Causing this error :

src/main.ts:9:32
TS2345: Argument of type 'BootstrapVuePlugin' is not assignable to parameter of type 'Plugin_2'.
  Type 'BootstrapVuePlugin' is not assignable to type '{ install: PluginInstallFunction; }'.
    Types of property 'install' are incompatible.
      Type 'PluginFunction<BvConfigOptions>' is not assignable to type 'PluginInstallFunction'.
        Types of parameters 'Vue' and 'app' are incompatible.
          Type 'App<any>' is missing the following properties from type 'VueConstructor<Vue>': extend, nextTick, set, delete, and 3 more.
     7 |
     8 |
  >  9 | createApp(App).use(router).use(BootstrapVue).mount('#app')
       |                                ^^^^^^^^^^^^
    10 |

Does anyone know a solution to this problem? Thanks in advance.

Guib answered 28/11, 2021 at 21:43 Comment(0)
Y
25

The current release of bootstrap-vue (v2.21.2) only supports Vue 2, but there's a GitHub issue tracking Vue 3 support (bootstrap-vue Issue #5196).

In the meantime, there is a third-party version that supports Vue 3:

  1. Install bootstrap and bootstrap-vue-3:
npm i -S bootstrap bootstrap-vue-3
  1. Initialize bootstrap-vue-3 in main.ts:
import { createApp } from 'vue'
import BootstrapVue3 from 'bootstrap-vue-3'

// Since every component imports their Bootstrap functionality,
// the following line is not necessary:
// import 'bootstrap'

import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue-3/dist/bootstrap-vue-3.css'

const app = createApp(App)
app.use(BootstrapVue3)
app.mount('#app')
Yankeeism answered 28/11, 2021 at 22:6 Comment(2)
"This package is deprecated and the repo was moved to bootstrap-vue organization. For updates on this project go to bootstrap-vue. The new package is called bootstrap-vue-next." (npmjs.com/package/bootstrap-vue-3)Aby
bootstrap-vue-next is working reasonably well.Illuse

© 2022 - 2024 — McMap. All rights reserved.