The Swiper Slider export called 'Navigation' is not available

Currently, I am working on a project utilizing the Quasar Framework and aiming to integrate the swiper slider. After successfully installing it using the npm command, I verified its version as

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ae9edf3eaffe8daababb4abb4aba8">[email protected]</a>
. However, when attempting to insert the styling in the quasar.config.ts file, I encountered a 404 error for the CSS bundle. The section of code in the quasar.config.ts file is as follows:

 css: ['app.scss', 'swiper/swiper-bundle.css'],

On the contrary, if I remove the bundle and try to utilize it without, I faced the following error message:

Uncaught SyntaxError: The requested module '/node_modules/.q-cache/vite/spa/deps/swiper.js?t=1725545338593&v=dd38fd58' does not provide an export named 'Navigation' (at SwiperSlider.vue:24:22)

Provided above is my SwiperSlider.vue code snippet.

<template>
  <div>
    <swiper
      class="mySwiper"
      :slides-per-view="1"
      :navigation="true"
      :pagination="true"
    >
      <swiper-slide>Slide 1</swiper-slide>
      <swiper-slide>Slide 2</swiper-slide>
      <swiper-slide>Slide 3</swiper-slide>
    </swiper>
  </div>
</template>

<script setup lang="ts">
import { Swiper, SwiperSlide } from 'swiper/vue';
import 'swiper/css';
import 'swiper/css/navigation';
import 'swiper/css/pagination';
</script>

<style scoped>
.mySwiper {
  width: 100%;
  height: 300px;
}
</style>


Without incorporating navigation and pagination, I am unable to use buttons for swiping through other slides. Kindly inform me if additional information is required. Thank you in advance! (Note that in Quasar Framework projects, there are no main.ts or main.js files unlike Vue projects)

List of attempted solutions:

  1. I added the CSS bundle in the quasar.config.ts file as mentioned earlier (Did not work)
  2. I tried running it without the bundle, importing the bundles in the component (Did not work)
  3. Consulted GPT-4 but did not receive a suitable solution
  4. Modified syntax from <script setup> to
    <script setup lang="ts">
  5. Checked queries/answers on Stack Overflow, yet unsuccessful in finding desired solution

[vue-tsc] Cannot find module 'swiper/vue' or its corresponding type declarations. /Users/tolgahandayanikli/Desktop/Quasar Dashboard/src/components/Miscellaneous/SwiperSlider/SwiperSlider.vue:17:37 15 | 16 |

17 | import { Swiper, SwiperSlide } from 'swiper/vue'; | ^^^^^^^^^^^^ 18 | import 'swiper/css'; 19 | import 'swiper/css/navigation'; 20 | import 'swiper/css/pagination';

Answer №1

If you're utilizing the swiper/vue component, it's recommended in the documentation to switch to using Swiper Element (Web Component) for simplicity.

To do so, create a file named swiper.js in the Quasar's boot directory:

src/boot/swiper.js

// import function to register Swiper custom elements
import { register } from 'swiper/element/bundle';
// register Swiper custom elements
register();

Next, add swiper as a boot file in your quasar.config.js:

quasar.config.js

export default configure((/* ctx */) => {
  return {
    // https://v2.quasar.dev/quasar-cli/boot-files
    boot: ["swiper"],
    ...
  }
})

This setup will enable swiper to work seamlessly within your Vue + Quasar project without the need to import anything into your .vue component file.

Solving console warnings

Although the swiper elements may function correctly, warnings might pop up in the browser dev console about failed element resolution. To address this issue, find "viteVuePluginOptions" in your quasar.config.js and make this modification:

quasar.config.js

viteVuePluginOptions: {
  template: {
    compilerOptions: {
      isCustomElement: (tag) => tag.includes("swiper"),
    },
  },
},

Once implemented, these warnings should no longer appear.

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

The function Event.preventDefault seems ineffective when attempting to block input of CJK (Korean) characters in a v-text-field of type

Currently, I am tackling an issue in a Vue project where I need to fix a small bug. However, the solution seems quite challenging. I have managed to make the v-text-field accept only numerical input, which is functioning well. <v-text-field type=" ...

What to do when encountering the error "Exceeded Maximum Call Stack Size in vue-router"?

Hello there, I am facing the following error: [vue-router] uncaught error during route navigation: vue-router.esm.js:1897 RangeError: Maximum call stack size exceeded at String.replace (<anonymous>) at resolvePath (vue-router.esm.js:597) ...

VueJS Process displays an error message stating 'undefined'

Having trouble accessing process variables in my Vue app. Despite trying various methods, I still can't seem to figure it out. Ensured that my .env file is located in the root directory Have run build and serve each time I add variables to the .env f ...

Exploring TypeScript: Determining the data type of an object key within the object

Apologies for the vague title, I'm struggling to articulate my problem which is probably why I can't find a solution! Let me illustrate my issue with a snippet of code: type Type<T> = { key: keyof T, doStuff: (value: T[typeof key]) =& ...

Although React .map may seem like a function, it does not work for passing arrays in

My application root contains a lazyloaded component. App root : import Component from './app/components/component/component.lazy'; class App extends React.Component{ stuff: stuffType[] = [1, 2 , 3]; render() { return ( ...

Strange Appearance of Angular Material Slider

I am experiencing some issues with my slider and I'm not exactly sure what's causing them. [] .big-container { display: block; padding-left: 10px; padding-right: 10px; padding-top: 10px; margin-bottom: 10px; } .question { display ...

"Configuration files for webpack and Vue: webpack.config.js and vue.config

Just recently diving into exploring Vue, I decided to kick off a project from the ground up. My current requirement is to incorporate vuetify. But it dawned on me that I lack both webpack.config.js and vue.config.js. Is it necessary for me to utilize npm ...

What is the best way to create a list from a matrix using JavaScript?

I have an array structured as follows: const input_array= [ ["red", "green"], ["small", "medium"], ["x", "y", "z"] //... can have any number of rows added dynamically ...

Exploring a JSON Object in TypeScript: A Step-by-Step Guide

I am currently utilizing Angular 7 and have a query that returns JSON data with a specific format: [ { "text": "test 1", "value": "1", "nbr": "1", "children": [ { "text": "test 1_1", ...

Combining React Conetxt with useReducer and Typescript throws the error message: 'No overload matches this call'

Here is a sample of my reducer code: import { IState } from "./initialState"; import { TAction } from "./actions"; import * as types from './types'; const myReducer = (state: IState, action: TAction): IState => { const ...

Using React's useState hook with an empty array

interface Crumb { title: string; url: string; } interface Crumbies { crumbsArray: Crumb[]; } // component const [breadcrumbs, setBreadcrumbs] = useState<Crumbies>([]); I encountered an issue: TS2345: Argument of type 'never[]' is ...

Embracing Typescript version 2.7 and above allows for utilizing multiple types within a parameter, enabling developers to efficiently handle specific properties

Imagine a scenario where a ChildClass is extending the ParentClass. You can view the code on Stackblitz here. The ChildClass simply adds a public property called "brainPower": class ParentClass{ _me: string; constructor() { this._me = "I'm ...

"Encountered an error: 'Unexpected token export' while working on an Angular application using SystemJS and

Inquiry: perplexing "Unexpected token export" Recently encountered this issue in an Angular demo hosted on plunker where SystemJS is used to transpile TypeScript code directly in the browser. The code was flawless and operated smoothly on my local syste ...

What methods does Angular use to determine the parameter types of a constructor?

I've been experimenting with replicating Angular's approach to interpreting the constructor in an injectable service. function Injectable() { return function<T extends { new (...args: any[]): {} }>(con: T) { return class extends con ...

Is there a way to utilize an AXIOS GET response from one component in a different component?

I'm having trouble getting my answer from App.tsx, as I keep getting an error saying data.map is not a function. Can anyone offer some assistance? App.tsx import React, {useState} from 'react'; import axios from "axios"; import {g ...

Utilizing Prisma Enum with Nest JS: A Comprehensive Guide

While working on my backend with Prisma and NestJS, I have encountered an issue. I defined an enum in Prisma that works fine in debug mode, but when I generate the Prisma client using nest build, I get an error. Object.values(client_1.RoomSharingType).join ...

Vue3 CLI constantly inquires about poor internet speed

While conducting an end-to-end test process, I set up Vue3 automatically using Vue CLI with the following command: npx --yes @vue/cli create vue3 --packageManager npm -n -i '{"useConfigFiles":true,"plugins":{"@vue/cli-plugin-b ...

How to minimize scaffolding with Redux, React, and Typescript?

Is there a way to avoid the process of instrumenting my Redux-Aware components? The level of scaffolding required seems excessive. Take, for instance, the minimal code necessary to define a redux-aware component: class _MyActualComponent extends React.Co ...

Prevent the Vue page from loading until the data has been fetched successfully

I'm in the process of finding a way to prevent my page from loading until my fetch task is completed. I'm facing some issues that need to be addressed: I have to re-fetch the data each time because I can't reuse the same data. (Changing vie ...

Struggling to get the bindings to work in my Angular 2 single-page application template project

I have recently started using the latest SPA template within Visual Studio 2017: https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp.net-core-with-javascriptservices/ The template project is functioning properly. ...