Guide to using vite-plugin-rewrite-all in conjunction with Quasar for Vue 3 - or alternative method to enable periods in paths

Encountering a 404 error when using quasar+vite in vueRouterMode: 'history' mode with paths containing a period/dot in the id? This issue has been discussed in various places:

Many recommend using vite-plugin-rewrite-all, but implementing it may not be straightforward. The suggested usage is as follows:

// vite.config.js
import pluginRewriteAll from 'vite-plugin-rewrite-all';

export default {
  plugins: [pluginRewriteAll()]
}

Referencing the documentation doesn't seem to resolve the problem. Importing or requiring the ES Module in quasar.config.js leads to errors like:

# Using:
# import pluginRewriteAll from 'vite-plugin-rewrite-all'

SyntaxError: Cannot use import statement outside a module
# Using:
# const pluginRewriteAll = require('vite-plugin-rewrite-all')

Error [ERR_REQUIRE_ESM]: require() of ES Module ./node_modules/vite-plugin-rewrite-all/dist/index.mjs not supported.
Instead change the require of ./node_modules/vite-plugin-rewrite-all/dist/index.mjs to a dynamic import() which is available in all CommonJS modules. code: 'ERR_REQUIRE_ESM'

Seeking assistance from anyone familiar with resolving this issue!

Answer №1

After some trial and error, I was able to get my quasar.config.js set up properly for it to work:

module.exports = configure(async function(/* ctx */) {
  const pluginRewriteAll = await import('vite-plugin-rewrite-all')
  return {
    build: {
      vitePlugins: [
        pluginRewriteAll.default()
      ]
    }
  }
})

I had to change the export function to async and use await for the import. While I'm not entirely convinced this is the optimal solution, it does seem to be effective.

Fortunately, Vite 5 seems to address this issue inherently, so I am eagerly anticipating the @quasar/app-vite v2 GA release, which should support it.

Update:

Apparently, vite-plugin-rewrite-all v1.0.2 encounters a problem loading as an ESM. If you stick with v1.0.1, the following approach also works:

const pluginRewriteAll = require('vite-plugin-rewrite-all')
module.exports = configure(function(/* ctx */) {
  return {
    build: {
      vitePlugins: [
        pluginRewriteAll.default()
      ]
    }
  }
})

This method feels more straightforward and less like a workaround.

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

Unable to view cross domain cookies within the browser's development tools

I am currently working on a web application that has an Angular front end running on http://localhost:4200 and a NodeJs backend running on http://localhost:3000. When a user successfully logs in, a cookie is set from the backend containing a token. However ...

Issue with ForwardRef component in Jest for React Native testing

When attempting to write a test case for my Post Detail screen, I encountered an error that stated: error occurred in the <ForwardRef> component: Here is my test class code: import React from "react"; import { NewPostScreenTemplate } from ...

React- Error: Unhandled Type Mismatch in function call for _this4.getNotes

As I delve into learning React, I've created a basic application to manage notes with titles and descriptions. This application interacts with a REST API built using Go, enabling me to perform operations like retrieving, editing, creating, and deleti ...

Seeking assistance with transferring jQuery to regular JavaScript and installing on the home screen of an Apple device

Dealing with the issue of iPhone "Bookmark to Homescreen" removing cookies and sessions, I have come up with a jQuery solution. Learn more about this problem here. In essence, by using JavaScript to create add to homescreen kit launch links, you can avoi ...

How can I implement API redirection in my Node.js application?

Currently, I am working on a mock authentication system in Node.js using passport and JWT. I have successfully created an API and I am using handlebars for templating. My dilemma arises when a user tries to login by sending their credentials to the API. I ...

Challenges arise when incorporating interfaces within a class structure

I created two interfaces outside of a class and then proceeded to implement them. However, when I tried to assign them to private properties of the class, something went wrong and I'm unable to pinpoint the issue. Can anyone offer assistance with thi ...

Change the boxShadow and background properties of the material-ui Paper component

I am currently referencing their documentation found at this link in order to customize default Paper component properties. Below is the code snippet I have: import { styled } from '@mui/material/styles'; import { Modal, Button, TextField, Grid, ...

Error: Unable to locate module 'child_process' in the context of NextJS + Nightmare

Encountering an issue while trying to compile a basic example using Next JS + Nightmare Scraper. Upon attempting to access the page, I am faced with the following error message, and the page fails to load. PS C:\Users\lucas\Documents\Pr ...

Is it possible in Vuetify 2 to align the items within the expansion of a v-data-table with the headers of the main component?

I am currently working on rendering a v-data-table where the expandable section serves as a "panel" title and I want the data inside the expansion to align with the headers set at the root level. Despite my efforts, I have not been able to find a way in th ...

Can someone show me how to use the IN operator in a PostgreSQL query in an Express.js (Node.js

My Approach to Writing Code var employees=[1,2,3]; await client.query( "SELECT user_id FROM group_user WHERE user_id IN($1)", employees ); An error is thrown indicating that only one parameter needs to be provided ...

Unique title: "Implementing Unique Event Handlers with VueJS Components"

My VueJS and Buefy project begins with two distinct click actions: Click on the Cyan area -> redirects to another page (Action 1) Click on the Magenta area -> shows a dropdown menu (Action 2) https://i.stack.imgur.com/AVLOS.png However, when clic ...

Can you provide guidance on transforming a JSON date format like '/Date(1388412591038)/' into a standard date format such as '12-30-2013'?

I have a json that is created on the client side and then sent to the server. However, I am facing an issue with the conversion of the StartDate and EndDate values. Can someone please assist me with this? [ { "GoalTitle": "Achievement Goal", ...

What are some ways to keep text within the boundaries of a div element?

I have tried multiple solutions for this issue, but none seem to be working for me. When I append a paragraph to a div, the text extends beyond the element. Below is the code I am using. Any assistance would be greatly appreciated. CSS: .chat-h { margi ...

Get the username from Parse instead of using the ObjectID

When using angular and Parse for JavaScript, I have implemented a search field where an admin can input the objectid of a user to display their details. However, I would like to modify this functionality so that the admin can enter the username instead of ...

Exploring the utilization of functions beyond module exports

Striving to clearly communicate my intentions, please feel free to ask if anything is unclear. Within a file named www, I am configuring my socket as follows: var server = http.createServer(app); var io = require('socket.io')(server); require(& ...

Paste a data point from an Excel spreadsheet into a JavaScript script

I'm encountering a major challenge. Currently, I am creating a login process for a client and here is the approach I have taken: function Jump(pal){ if (pal=='10528'){window.open('http://www.google.es','_parent')} Subs ...

How to effectively delete the class from a navigation list item

Looking for some inspiration? Check out the basic visuals for this question here. But let me break it down for you. This snippet shows the HTML & CSS behind a tabbed-carousel, with a condensed version for clarity: <style> #myCarousel-100 . ...

The Vuetifyjs 2.0 theme remains unchanged despite using watchers

When working with Vuetifyjs v1.5, I was able to easily change the theme dynamically using Vue watchers. However, this functionality seems to have changed with the update to Vuetifyjs 2.0. Current Versions: Vue - 2.6.10 Vuetify - 2.0 Vuex - 3.1.1 export ...

What is the method of utilizing shared services when the controllers do not rely on any shared services?

Let's imagine a scenario where there is a module containing only one factory, which serves as the shared service. angular.module('sharedService', []) .factory('sharedSrv', sharedService) function sharedService() { var numbe ...

Is there a way to verify the selection of all mandatory fields prior to concealing a div?

var count = 2; $('.next').click(function() { var requiredField = true; $(this).siblings('table').find('tbody tr:nth-child(' + count + ') td').each(function() { var element = $(this).find('center').f ...