Any tips on incorporating styled-components and local fonts in Next.js?

Recently, I integrated styled-components into my Next.js application. To make it work, I had to include a Babel file with the following code:

{
    "presets": ["next/babel"],
    "plugins": [["styled-components", { "ssr": true }]]
}

Next, I wanted to use a local font and followed the guidelines outlined in the documentation here. However, I encountered an issue where the app started throwing errors after implementing the local font. The error message indicated that I needed to revert back to using the initial Babel configuration.

My question is: how can I successfully utilize both styled-components and a local font in my Next.js application without causing any conflicts or errors?

Answer №1

Enhance your Next.js experience with the latest release of version 12, which now supports styled-components without requiring additional plugins.

To enable this feature, simply include styledComponents: true in your next.config.js file:

const nextConfig = {
  ...your existing configuration here,
  compiler: {
    styledComponents: true,
  },
};

module.exports = nextConfig;

For more information and discussion on this topic, check out this related GitHub issue.

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

What is the best way to configure the loading state of my spinner?

When a user clicks to navigate to the articles page, I want to display a spinner while waiting for the articles data to be fetched and displayed. There is a slight delay after the click, hence the need for the spinner. I have a custom spinner component ca ...

Getting the accessToken for next-auth with Microsoft Graph API: A guide to obtaining your authentication token

I am currently in the process of developing an email marketing automation tool utilizing NextJS, next-auth, and Microsoft Graph API. To authenticate users, I have integrated next-auth's Azure AD B2C provider by referring to their documentation. Follo ...

What is the best way to retrieve cookies using getinitial props in Next.js?

Is there a way to retrieve cookies in getInitialProps and use them to fetch data from an API on a page in Next.js? ...

The provided property `verseObj.version_id` is not valid. It should be of type `object`, but a `string` value has been supplied

I am currently developing a unique and innovative public prayer journal that allows for the addition of verses in full stack. Surprisingly, I encountered an error when rendering the form which was not present a few days ago. Strangely enough, I have made n ...

Tips for setting a background image that covers the entire screen

Exploring Next.js after working with React, I am facing a challenge in setting a full screen background image for a hero section using styled components. While I have successfully achieved this in React using styled components with code similar to the exam ...

Guide on utilizing a search bar component for filtering results in a card component. ReactJS and NextJS integration

One component I have is the Search.jsx search bar: import { useEffect, useState } from 'react' export default function Search() { const [query, setQuery] = useState('') return ( <div className={styles.container}> ...

Where could the issue be with sending the Verification Email?

Hello everyone, I'm diving into the world of PayloadCMS as I embark on building a new webapp. Currently, I've reached the stage where I am attempting to implement email verification, but I seem to have hit a roadblock with an unfamiliar error. Th ...

Developing a Next.js application using Typescript can become problematic when attempting to build an asynchronous homepage that fetches query string values

Having recently started delving into the world of React, Next.js, and Typescript, I must apologize in advance if my terminology is not entirely accurate... My current learning project involves creating an app to track when songs are performed. Within the ...

What is the method to conceal the card icons displayed in the Stripe Payment Element?

Using Stripe Payment Element I am tasked with integrating Stripe payment for a client, but they specifically do not want the card icons (MasterCard, Visa, etc.) to be displayed. After attempting to hide them using Elements Appearance API without success, ...

Issues encountered while deploying Next.js on AWS Elastic Beanstalk

I encountered the following issue while deploying to AWS Elastic Beanstalk. Can anyone shed some light on why this error is happening? > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="36555a5f535842760618071806">[email& ...

Is it feasible to display components in reverse order using JSX?

I have a component in my Nextjs/React.js app where I display a list of cards like this : <div className="grid grid-cols-1 lg:grid-cols-12 gap-12"> <div className="lg:col-span-8 col-span-1"> {posts.map((post, ...

When utilizing getServerSideProps in Next.js for SSR, the graphql context may be found to be

I am encountering an issue with using getServerSideProps on my page: export const getServerSideProps: GetServerSideProps = async (ctx) => { const apolloClient = initializeApollo() await apolloClient.query({ query: UserQuery, variables: { id ...

What is the reason for the disappearance of bullets on my Tailwind-styled <ul> items when overflow-scroll is added?

Currently, I am in the process of developing a website with react and tailwind. In one section of the page, I would like to incorporate a vertical scrollbar for a list. However, upon doing so, the bullets within the list disappear. This has left me puzzled ...

Looking to customize scrolling behavior when navigating back in Next.js?

I have a function in my index.js file that fetches a list of posts like this: const Index = (props) => { return ( <div> {props.posts.map((each) => { return ( <Link scroll={false} as ...

The true nature of Next.js Server action is revealed - it actually returns a promise instead

After updating my Next.js version to 14.1.4, I encountered an issue in a client component when calling checkoutWithStripe. The return type of getURL has changed from a String to a Promise in this new version. I'm not sure why this change occurred as ...

Error: Unable to extract 'blog' property from 'param' because it is not defined in the Strapi NextJS context

I'm currently developing a blog using NextJS and Strapi. While implementing the comment functionality for my blog posts, I encountered two strange errors: TypeError: Cannot destructure property 'blog' of 'param' as it is undefined. ...

Using NEXT JS, Three js is able to convert an equirectangular panorama into cubemap format

I'm currently working on converting an equirectangular panorama image into cubemap format using NEXT JS. The scene is being rendered but I'm facing an issue where the background isn't applying, and surprisingly, no errors are showing up! im ...

Retrieving data in [slug].js using Reactjs

I am currently working on a project in Reactjs utilizing the "nextjs" framework. I have successfully managed to retrieve data (specific blog details) based on the slug([slug.js]). However, I now need to display data from all other blogs within the same c ...

Issue encountered: Next.js has failed to hydrate properly due to a discrepancy between the initial UI and server-rendered content

Uncertain about the cause of this error? The error seems to disappear when I remove the provided code segment. What is triggering this error in the code snippet and how can it be fixed? <div className="relative flex flex-col items-center pt-[85.2 ...

What is the best way to merge an array of objects into a single object?

Is there a way to dynamically convert object1 into object2, considering that the keys like 'apple' and 'water' inside the objects are not static? const object1 = { apple:[ {a:''}, {b:'&apos ...