Guide to integrating Bootstrap-Vue / Vue 2 with Vite

In the process of migrating my project from webpacker to vite, I encountered some Bootstrap Vue issues such as

Multiple instances of Vue detected
and $attr and $listeners is readonly, which are detailed in BootstrapVue's documentation here

Previously, in webpacker, I addressed these issues by configuring my setup like this:

const resolver = {
   resolve: {
      alias: {
         'vue$': 'vue/dist/vue.esm.js'
      }
   }
};

environment.config.merge(resolver)

Attempting to replicate this fix in vite, I added the following code snippet to my vite.config.ts file, but it didn't work as expected:

import {defineConfig} from 'vite'
import RubyPlugin from 'vite-plugin-ruby'
import {createVuePlugin} from "vite-plugin-vue2";

export default defineConfig({
    plugins: [
        RubyPlugin(),
        createVuePlugin()
    ],
    resolve: {
        alias: {
            'vue$': 'vue/dist/vue.esm.js'
        }
    }
})

So, my question is: what would be the recommended solution to overcome this issue?

Answer №1

When encountering duplication issues, Vite offers a solution with the resolve.dedupe setting:

export default defineConfig({
  resolve: {
    dedupe: ['react', 'react-router'],
  },
})

Typically, react does not require this configuration and functions well by default.

Consider removing the react$ alias and updating imports to use react; Vite should automatically handle optimization and correct import resolution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Redux: streamlining containers, components, actions, and reducers for seamless organization

Here's the question: When working on a large React/Redux application, what is the most effective and sustainable method for organizing containers, components, actions, and reducers? My take: The current trend leans towards organizing redux elemen ...

Send information and showcase it on the following screen using ReactJS

Having recently started using ReactJS for a front-end development project, I encountered a challenge that I need help with. I want to prompt the user for their name using an input field after a question like "What is your name?". Once the user inputs their ...

Transforming React drag and drop page builder state into a functional html, css, and js layout

Currently, I am in the process of developing a drag and drop UI builder for react-based app frameworks. Before incorporating drag and drop functionality, my main focus is on rendering a page layout based on a structured array stored in the state. https:// ...

Adding middleware to the res.render() function can be extremely helpful when dealing with a large number

Recently, I put together a webpage for local use and it involves many routes. Specifically, I have 31 .ejs files and 3 .html files all neatly stored in the "views" folder. //app.js - using node and express app.get('/page1', function(req, res ...

Download CSV file directly in Internet Explorer 10 by choosing to open the file instead of saving it on your device

On my server, I have a link available to download a file: <a id="downloadCSVFile" runat="server" href="javascript:void(0)" onclick="parent.document.location = 'CSVFile.csv';">Download</a> I attempted this method as well: <a id=" ...

What might be causing the issue in passing the user_name value into my component, particularly in the authentication process?

After authenticating, I am facing an issue with passing the user's name into a Vue component. Upon loading, I receive a name: undefined value. This is the content of my AuthService.js: //config details extracted from OAUTH JS doc: https://github ...

Utilizing JSON API filtering within a Next.js application

Recently delving into the world of coding, I've embarked on a personal project that has presented me with a bit of a challenge regarding API filtering. My goal is to render data only if it contains a specific word, like "known_for_department==Directin ...

"Losing focus: The challenge of maintaining focus on dynamic input fields in Angular 2

I am currently designing a dynamic form where each Field contains a list of values, with each value represented as a string. export class Field { name: string; values: string[] = []; fieldType: string; constructor(fieldType: string) { this ...

Organize array by year and month groupings

I'm trying to organize an array of events by year and month. Here is a sample of my data: const events = [ { name: "event 1", year: 2021, month: 1, }, { name: "event 2", year: 2021, month: 9, }, { ...

Show a variety of pictures in a random arrangement?

Looking for some help here! I'm trying to shuffle my images in a random order each time the page is refreshed. It's like a game of musical chairs but with pictures! Does anyone know how to achieve this? I've done some searching, but haven& ...

Revoking existing Json Web Tokens when updating user information

Once a user logs in with their username and password, they receive an access_token containing the payload that includes their uniqueTokenIdentifier. This unique identifier is stored for each user in the database. If a user changes their password due to ac ...

Dockerized Vue.js application experiencing issues with port exposure

I am working on a simple vue.js app and have created a dockerfile for it: FROM node:latest WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run generate EXPOSE 3000 CMD ["npm", "run", "start"] When I try to run it using: docker r ...

Tomcat encounters difficulty accessing the JavaScript directory

Seeking assistance with my first question regarding Angular tutorials. When I deploy to test the script, I encounter an HTTP 404 error. I have tried various solutions suggested for similar issues without success. It appears to be a path problem as the ang ...

What is the best way to uncheck a checkbox once both of my input fields [type=text] have been cleared or are empty

Is there a way to uncheck the checkbox input if both text inputs are empty, and check it if one of the text inputs is filled? $('input[name="t2"],input[name="t3"]').keyup(function() { $('input[name="t1"]').prop("checked", $.trim($( ...

Retrieve the outermost shell of the VUEjs wrapper test-utils

While working on a VueJS test, I encountered an issue where accessing the outermost layer of HTML seemed impossible. No matter what methods I tried, the outermost layer was always ignored. Is there a way to gain access to this outermost layer so that I c ...

I'm unsure about the JavaScript toolkit framework's handling of selecting HTML class attributes

I have been exploring the Electron Framework using a JavaScript toolkit known as Xel. In my main.js file, I am working with the following syntax: document.querySelector("menu.selected").className.remove('selected') In my Xel code snippet, I hav ...

What strategies can I employ to access data from an Ajax POST call beyond its original return function?

I am facing an issue with my jQuery Ajax POST call that runs a PHP script and retrieves data. The problem lies in accessing this data outside the success function. Even though I have declared a global variable components, it seems to lack scope within the ...

Why won't the Laravel Livewire click function work after the PJAX container refresh?

I am currently using the pjax library in my application, and I recently integrated Livewire. However, I am facing difficulties in making them work together. Specifically, my issue is as follows: In my application, I have a grid displaying products with an ...

Leverage the power of ExpressJS by seamlessly sharing route middleware between routes

Looking for a way to share multiple route middleware across various routes and controllers? Check out this setup: In app.js, we require ./routes/index.js: // load fs module var fs = require('fs'); // import routing files module.exports = func ...

Moving a session between a window and a modal dialog box

When I open a modal dialog from a parent window using a button click, everything works fine in WinXP with IE8. However, in Win7 with IE8, I encounter an issue where the modal dialog takes me to the login screen. Oddly enough, if I enter my credentials, clo ...