Issues with style implementation in React-responsive-carousel

I've been trying to integrate the react-responsive-carousel into my NextJS project. Everything appears to be working fine when I run npm run dev, but unfortunately, my carousel is showing up without any styles.

import { Carousel } from 'react-responsive-carousel';
import 'react-responsive-carousel/lib/styles/carousel.min.css'; // requires loader

const MyCarousel = () => {
   return (
        <Carousel
            autoPlay
            interval={2500}
            showArrows={true}
        >
            <div>content</div>
            <div>content</div>
            <div>content</div>
       </Carousel>
   )
}

According to the documentation, the styles require a loader. So, I made changes to my next.config.js as shown below:

const withLess = require('@zeit/next-less');
const withCss = require('@zeit/next-css');
const withImage = require('next-images');
const theme = require('./app/styles/antdoverrides');

module.exports = withImage(
withCss({
    cssModules: true,
    optimizeFonts: false,
    ...withLess({
        lessLoaderOptions: {
            javascriptEnabled: true,
            importLoaders: 0,
            modifyVars: {
                ...theme,
            },
        },
        cssLoaderOptions: {
            importLoaders: 3,
            localIdentName: '[local]___[hash:base64:5]',
        },
        webpack5: false,
        webpack: (config, { isServer }) => {
            if (isServer) {
                const antStyles = /antd\/.*?\/style.*?/;
                const origExternals = [...config.externals];
                config.externals = [
                    (context, request, callback) => {
                        if (request.match(antStyles)) return callback();
                        if (typeof origExternals[0] === 'function') {
                            origExternals[0](context, request, callback);
                        } else {
                            callback();
                        }
                    },
                    ...(typeof origExternals[0] === 'function' ? [] : origExternals),
                ];

                config.module.rules.unshift({
                    test: antStyles,
                    use: 'null-loader',
                });
            }
            return config;
        },
    }),
}),


);

Despite these changes, I'm still not seeing the expected outcome. Any suggestions or tips would be greatly appreciated.

Answer №1

Make sure to include your styles by importing them in your _app.js file if you're not using the objects. Simply add an import statement for your styles within your _app file, like so:

import "../styles/globals.css";

Additionally, run npm run local or a similar command as specified in your package.json file to locally run your project instead of building it.

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

Transferring information from one page to the next

How can I efficiently transfer a large amount of user-filled data, including images, between pages in Next.js? I've searched through the Next.js documentation, but haven't found a solution yet. ...

Utilize an imported function within a React component's return statement to avoid an invalid hook call issue

Hey everyone, I've created a reusable component that can translate keys into a chosen language using keynames as strings or variables. Typically, I would use a <t> tag for this purpose, but due to certain reasons, I am replacing current transl ...

Creating a see-through cursor resembling the one found on the App Store using CSS

Currently, I’m struggling a bit with understanding how to accomplish this task: The issue is that the pointer/arrow within the nav-element appears transparent and displays the content rather than its parent, which is the nav-element. Here is my HTML co ...

How does thinking in ReactJS differ for someone with an AngularJS background?

Although I have experience with AngularJS, I am eager to dive into the world of ReactJS. I'm particularly intrigued by ReactNative and its potential to transform mobile apps. Can you explain how the mindset and architecture of a React application co ...

Encountering a 404 error while trying to retrieve the service-worker in a PWA app hosted on firebase with next

I am encountering a 404 error when trying to fetch the service-worker on my PWA app built with next.js and hosted on Firebase. I have integrated the service-worker into this application, which is based on the repository provided in the link below: https:/ ...

The setState function does not seem to be properly updating when adding new state values

While working on my react-beautiful-dnd project, I encountered an issue where the state does not update after creating a new column by clicking a button. Even though the newState is displayed correctly when using console.log(newState), the original state ...

What's the key ingredient I need to add for a dropdown navigation menu?

What am I overlooking in my HTML and CSS coding to create a standard list dropdown in my navigation menu? When I preview this section of the page in Chrome and IE, the navigation area appears fine until I hover over the Fishing and Guides link. Instead of ...

Toggler for the Bootstrap navbar

Recently, I've been experimenting with Bootstrap for the first time and trying to understand its functionalities. While I've managed to make some progress with navbars, I've encountered a roadblock when it comes to the navbar-toggler. <n ...

NextJS - Error: Invalid JSON format, starting with a "<" symbol at position 0

After following a tutorial on NextJS, I attempted to make some modifications. My goal was to include the data.json file on the page. However, I kept encountering the error message "Unexpected token < in JSON at position 0." I understand that I need to ...

React useEffect cleanup will only be triggered when the component is unmounting

I am looking to create an alert when a component is dismounted using React hooks. Here is an example: const [checked, setChecked] = useState(false); useEffect(() => { return () => { if(checked) alert("Hi") }; }, []); ... However, ...

Cutting diagonally through a text along the trajectory of an SVG line

Is it feasible to have diagonal text cutting effect when an svg line overlaps with the text? Below is the code snippet and a visual representation of the desired outcome. <!DOCTYPE html> <html> <head><title></title> <sty ...

Foreground spotlight shines upon background button display

Apologies for any language barriers... I'm currently working on developing an E-commerce Website. The issue I am facing is that when I click the Add to Cart (Zum warenkorb hinzufügen) button and the window pops up with the + and - icons, they are v ...

What is the best way to determine the size of the URLs for images stored in an array using JavaScript?

I am working on a project where I need to surround an image with a specific sized 'div' based on the image's dimensions. The images that will be used are stored in an array and I need to extract the height and width of each image before disp ...

What is the best way to decrease the width of a textfield in jQuery mobile?

Is there a way to decrease the width of a textfield in jQuery mobile? Check out this Fiddle for reference The CSS provided below does not seem to be working properly: #co label{ color: red !important; width: 100px !important; margin :30px; ...

The styled options in mui Select drop down are not affected when applying scoped shadow DOM styles using the entry point

It's important to note that this solution is specifically for MUI v5 with @mui/material, not for v4 with @material-ui/core. After finally resolving the issue of displaying @mui/material styles when using an entry point to emotion for inserting scoped ...

Unable to change the background color of h1 tag in a ReactJS project

import React from 'react' export default function Home(){ return<div> <h1 className="bg-dark text-white p-3">Home Page</h1> </div> } I am attempting to modify the background color of the h1 tag in my Reac ...

Utilizing Angular's ng-if to dynamically adjust Twitter Bootstrap's column size with col

Here is the code snippet: left block right block This code displays the left block on the left side of the screen and the right block on the right side, adjusting for different screen sizes. If the screen i ...

Just getting started with JavaScript and running into trouble creating an array of image objects using an array of strings

I am struggling to accurately describe my issue, making it difficult to find a solution. I have an array called tempData generated from a text file that I want to reference with variables of the same name as the strings in the array. var red = new Image ...

Using jQuery to remove all inline styles except for a specific one

Just a quick inquiry: Our Content Management System (CMS) utilizes CKEditor for clients to modify their websites. The front-end styles include the use of a pre tag, which we have customized to our desired appearance. However, when their team members copy a ...

Encountering unanticipated breakpoints in compiled .Next files while using Visual Studio Code

As a newcomer to NextJS, I have encountered an issue that is disrupting my workflow. I followed the instructions in https://nextjs.org/docs/advanced-features/debugging#using-the-debugger-in-visual-studio-code to set up my launch.json file. Although I am ...