question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Cannot convert undefined or null to object` when using `Thumbs` module

See original GitHub issue

Check that this is really a bug

  • I confirm

Reproduction link

https://github.com/bnn1/swiper-issue

Bug description

When creating component from example in React app, app throws runtime error TypeError: Cannot convert undefined or null to object.

Reproduction link contains next.js app but it is possible to reproduce with pure react bootstrapped with CRA

Steps to reproduce:

  1. Create react app yarn create react-app
  2. Install swiper
  3. Create component Carousel and add the following code
code
import React, { useState } from "react";
import { Swiper, SwiperSlide } from "swiper/react";
import { Thumbs } from "swiper";
import "swiper/css";

export const Component = () => {
  // store thumbs swiper instance
  const [thumbsSwiper, setThumbsSwiper] = useState(null);

  return (
    <main>
      {/* Main Swiper -> pass thumbs swiper instance */}
      <h1>hello</h1>
      <Swiper modules={[Thumbs]} thumbs={{ swiper: thumbsSwiper || null }}>
        <SwiperSlide>1</SwiperSlide>
        <SwiperSlide>2</SwiperSlide>
        <SwiperSlide>3</SwiperSlide>
        <SwiperSlide>4</SwiperSlide>
        <SwiperSlide>5</SwiperSlide>
      </Swiper>

      {/* Thumbs Swiper -> store swiper instance */}
      {/* It is also required to set watchSlidesProgress prop */}
      <Swiper modules={[Thumbs]} watchSlidesProgress onSwiper={setThumbsSwiper}>
        {/* ... */}        <SwiperSlide>1</SwiperSlide>
        <SwiperSlide>2</SwiperSlide>
        <SwiperSlide>3</SwiperSlide>
        <SwiperSlide>4</SwiperSlide>
        <SwiperSlide>5</SwiperSlide>

      </Swiper>
    </main>
  );
};

4. Use `Component` inside `App.js` file
import { Component } from './Component';

function App() {
  return (
    <div className="App">
      <Component />
    </div>
  );
}

export default App;
  1. Run application yarn start
  2. Navigate to localhost:3000
  3. Open dev tools

Expected Behavior

No errors occur during runtime

Actual Behavior

Errors occur during runtime

Swiper version

8.1.0

Platform/Target and Browser Versions

Linux (arch), Chrome Version 100.0.4896.88 (Official Build) (64-bit)

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
  • Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • I’m willing to open a PR

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:12
  • Comments:15

github_iconTop GitHub Comments

176reactions
MaksimAmelchenkocommented, Apr 27, 2022

the workaround is thumbs={{ swiper: thumbsSwiper }} replace to thumbs={{ swiper: thumbsSwiper && !thumbsSwiper.destroyed ? thumbsSwiper : null }}

12reactions
linkb15commented, Apr 14, 2022

I am facing with this issue as well with Nextjs 12 + React 18

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swiper React cannot convert undefined or null to object
I tried using onSwiper prop to achieve this functionality but i ran into an error. thumbs.js:67 Uncaught TypeError: Cannot convert undefined or ...
Read more >
Cannot convert undefined or null to Object in JavaScript
The "Cannot convert undefined or null to Object" error occurs when we pass a null or an undefined value to a function that...
Read more >
Cannot convert undefined or null to object ( But we didn't ...
Hi Retool team, Since this morning, we have this error message that appears (Cannot convert undefined or null to object).
Read more >
Cannot convert undefined or null to object - Code Grepper
I had this issue when compiling using my global truffle module. i switched to npx truffle compile after installing it as a dev...
Read more >
npm err! cannot convert undefined or null to object - You.com
Since you updated the weback cli version you probably had to update something else for it to work properly but you did not,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found