GithubHelp home page GithubHelp logo

Comments (13)

cpiocova avatar cpiocova commented on June 12, 2024 18

Hello, I hope to help you. It worked like this for me:

import the two css files into _app.js

It would look like this:

import App from "next/app";
import "owl.carousel/dist/assets/owl.carousel.css";
import "owl.carousel/dist/assets/owl.theme.default.css";
class MyApp extends App {
render() {
const { Component, pageProps } = this.props;
return (
<Component {...pageProps} />
)}};

export default MyApp;

In next.config.js add

const withPlugins = require("next-compose-plugins");
const withImages = require("next-images");
const webpack = require("webpack");
module.exports = withPlugins([withImages], {
webpack: (config) => {
config.node = {
fs: "empty",
};
config.module.rules.push({
test: /\.(glb|gltf|bin)$/,
use: {
loader: "file-loader",
},
});
config.plugins.push(
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
}));
return config;
},
});
PD: The important thing here is to configure webpack with jquery

In the file where they use the OwlCarousel. In my case in Testimonials.js

import React from "react";
import dynamic from "next/dynamic";
const OwlCarousel = dynamic(import("react-owl-carousel"), {
ssr: false,
});
function Testimonials() {
return (
<OwlCarousel className="owl-theme" loop margin={10} nav>
...
</OwlCarousel>
)}
`

from react-owl-carousel.

ibrhmvci avatar ibrhmvci commented on June 12, 2024 7

@nayyir-haulerads thank you ! I'm using nextjs and I imported owlcarousel like this ;
import dynamic from 'next/dynamic';
const OwlCarousel = dynamic(import('react-owl-carousel'));
then in my main component;
state= { display:false};
componentDidMount(){ this.setState({display:true}) }
and finally returned like that ;
<div className="container slider-container">
{this.state.display ? <MyOwl/> : <div></div>}
</div>
first components mounts and sets state to true .then next/dynamic loads owl-carousel library and it works.

from react-owl-carousel.

cscottsa avatar cscottsa commented on June 12, 2024 5

Hi @rh0delta , I tried everything possible. It has to do with style-loader webpack uses and the library. The library exposes the "window" object which the server-side does not have, so when it tries to preload the page on the server the app crashes, because the object does not exist.

I found a alternative, which does Exactly the same thing and works perfectly, except a very small bug, which isn't really a bug. (last link)

react-slick:
https://github.com/akiran/react-slick

If you decide to use custom arrow components, just create your component as below:
akiran/react-slick#671

from react-owl-carousel.

rh0delta avatar rh0delta commented on June 12, 2024 1

Were you able to determine the cause of this issue because I am now receiving the same error.

from react-owl-carousel.

nayyir-haulerads avatar nayyir-haulerads commented on June 12, 2024

I was able to get around the web pack errors with using the cdns for owl carousel, and using componentDidMount to initialize carousel object.

from react-owl-carousel.

valeriashpiner avatar valeriashpiner commented on June 12, 2024

Unfortunately, I have the same issue with my server-side rendering.
I will use alternative slider, but I would be happy if this issue will be fixed, because I like owl-carousel.

from react-owl-carousel.

nayyir-haulerads avatar nayyir-haulerads commented on June 12, 2024

Hi @valeriashpiner, if you just include the original cdns for owl carousel 2 and initialize the carousel for your objects using ReactDOM to find the element within componentDidMount it will work

from react-owl-carousel.

ibrhmvci avatar ibrhmvci commented on June 12, 2024

Isn't there any solution yet ? @nayyir-haulerads can you be more specific and give some details please ? @valeriashpiner what "alternative slider" you used ?

from react-owl-carousel.

nayyir-haulerads avatar nayyir-haulerads commented on June 12, 2024

@ibrhmvci the solution that I have found, and continue to use, is to load the owl carousel library from its cdn, rather than using the node package. After loading the cdn you will have access to the owlCarousel function globally. Whichever component you decide to use to render the carousel be sure to add a β€œref” attribute to carousel component and call owlCarousel on the element within componentDidMount().

from react-owl-carousel.

nayyir-haulerads avatar nayyir-haulerads commented on June 12, 2024

Hope that helps

from react-owl-carousel.

NextTrick avatar NextTrick commented on June 12, 2024

Hi @nayyir-haulerads, can you show your solution in code?

from react-owl-carousel.

sharath-tenet avatar sharath-tenet commented on June 12, 2024

Can anyone tell me the solution ?
TIA

from react-owl-carousel.

Eronmmer avatar Eronmmer commented on June 12, 2024

Can anyone share their solution? I'd really appreciate

from react-owl-carousel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.