Questions tagged [next.js]

Next.js stands as a sleek and streamlined framework, dedicated to crafting server-rendered React applications alongside the ability to export React apps in static format.

Having trouble establishing a connection with mongoose and typescript

When attempting to establish a connection using mongoose, I consistently encounter the errors outlined below. However, if I use MongoClient instead, everything functions as expected. import connectMongo from '../../lib/connectMongo' console.log("TRY ...

Exclude babel.config.js from being processed by Next.js

Currently, I am working on a Next.js application and I need to customize Babel in order to run my Jest test suite. The issue I'm facing is that when I configure the babel.config.js file, Jest runs successfully but Next.js also picks up this configurat ...

Error in Next.js: .env variable not defined

I recently transitioned my project from React to Next.js and encountered an issue where my environment variables are showing as undefined, even though they were functioning correctly in React. Can someone provide some guidance or assistance with this probl ...

Encountering a issue when trying to render an image retrieved from an API in Next JS

I encountered an issue where I am unable to retrieve the image from the API. Strangely, it works fine with the img tag but throws an error when switching to the NextJS Image tag. import React, { useState, useEffect } from "react"; import ...

Ways to resolve the issue "How to address the React hook error stating "React Hook 'React.useState' is being called conditionally"?"

I encountered an issue while attempting to build my next.js project. How can I resolve it? It seems that the error is related to using hooks conditionally. ./src/lib/session.js 6:29 Error: React Hook "React.useState" is called conditionally. R ...

Unable to transfer an array from getStaticProps method in Next.js

Whenever I pass a JSON array from getStaticProps in Next.js, I encounter this specific error message when trying to access it. TypeError: Cannot read property 'contentBody' of undefined module.exports../pages/[author]/[article].js.__webpack_exports__.defa ...

Implement a personalized loading spinner in your Next.js application

What is the process for implementing a custom loader in Next.js instead of using the default option? const loading = true; if (loading) { return <CustomLoading />} ...

What is the method for adjusting the Accept-Language header in axios using next-i18next outside of a component?

I have been working on exporting a custom function called setLanguageHeader in order to modify the Accept-Language header used by axios. In my axios file, I encapsulated the code as follows: requests.ts: import axios, { AxiosRequestConfig } from 'ax ...

Ways to incorporate a language switcher with next-intl

"use client"; import { useLocale } from "next-intl"; import { locales, localeNames } from "../../i18nconfig"; import { useRouter } from "next/router"; import Link from 'next/link'; import { Fragment } from ...

What steps do I need to take in order to implement a Next.js project using the http protocol in a production

Currently, I am in the process of creating an intranet webpage that will be hosted on a private network using Next.js. However, when the production-level Next.js web app is built and running, it forces the loading of files (CSS, JS, images) via the HTTPS ...

Developing NextJS 13 with App directory integration for socket.io

How do I initialize a socket in the app/api/socket/route.js directory? When referencing the example in the pages/api/socket.js directory, it seems that it does not return an instance of http.ServerResponse. Instead, it returns NextResponse, which does not ...

What are some ways to implement a pre-execution step, such as an interceptor, before Nextjs runs getStatic

When working with getStaticProps and getServerSideProps in Next.js, I need to intercept and add common header properties to all request calls that are executed server-side. axios.interceptors.request.use(function (config) { // Perform actions before ...

Ways to retrieve the currently selected id from the router within the next 14 steps

I'm currently trying to extract the ID that is selected (#about, #home, #blog) or the full path (http://localhost:3000/#about, http://localhost:3000/#home) from the router. I am working with Next.js version 14.0.3 This is my approach: My current URL ...

NextJS is encountering an issue with Axios' withCredentials functionality

I'm facing an issue where Axios is not sending the cookie to my backend API, even though I have set the withCredentials properly. Front-end (NextJS): import axios from "axios" const BASE_URL = "http://localhost:8000" export defa ...

"Adjusting the spacing between elements in Tailwind CSS can result in an unexpected layout appearance

I'm currently tackling a project in Next.js with Tailwind CSS enabled. Below is the code snippet from my page.tsx: export default function Page() { return ( <div className="flex flex-row flex-wrap items-center justify-center space-x-16 s ...

NextJs creates serverless applications using static HTML files rather than lambdas

As I work on developing an application using Next.js serverless, I am facing an issue where instead of generating JS files in the designated folder (next/serverless/pages/), my pages are being transformed into static HTML files. This is evident during the ...

Issue encountered with create-next-app during server launch

Encountering an error when attempting to boot immediately after using create-next-app. Opted for typescript with eslint, but still facing issues. Attempted without typescript, updated create-next-app, and reinstalled dependencies - unfortunately, the prob ...

Fixing scaling problems in Recharts: A troubleshooting guide

Currently, I am working on a React application using Next.js and trying to incorporate a graph feature using recharts from . Below is the code snippet I have implemented: /index.js const formatDate = (value) => { return moment.unix(value).format('HH: ...

What is the best way to add a button over an image using Tailwind CSS in Next.js?

I've been trying to display a button on top of an image using Tailwind CSS and Next.js, but I'm having trouble getting it to align properly. Here is the code snippet I've been working with: <div> <Image src={projectAiWriter} alt=&q ...

Unable to update latitude and longitude in state

Upon clicking on the map, I successfully retrieve the latitude and longitude coordinates which I then log in the console. However, when attempting to assign them to a state variable, I encounter the following error: https://i.stack.imgur.com/dwDaw.png I a ...

Creating a Docker image for NextJS with an nginx server

Exploring the realm of Docker as a newbie, I am immersing myself in its official documentation. My current venture involves fashioning a NextJS build with a docker image tailored for an nginx server, and here is my roadmap: Commencing by installing the es ...

Creating individual product pages from an array of objects: A step-by-step guide

Is there a way in Next.js to create individual pages for each object in an array with unique URLs? Here is the input array: Input Array const products = [ { url: "item-1", id: 1, name: "Item 1", description: "lor ...

Is it possible to utilize the OnBlur prop based on a certain condition?

To display a component when the input is focused, follow the steps below: Click here for not focused state When you click on the text input, the component should appear like this: Click here for focused state The code snippet provided works correctly. ...

The property 'currentUser' of 'Object(...)(...)' is unable to be destructured due to its null value

I keep encountering the error message "Cannot destructure property 'currentUser' of 'Object(...)(...)' as it is null" whenever I utilize the useContext() hook from React in my Next.js project. // Other imports import CurrentUserContext ...

The issue with the Shadcn dialog not closing when the submit button is pressed

I am currently utilizing the shadcn dialog component, and I made some adjustments to its default behavior. Initially, the submit button was functional even without any input in the fields, which was not my intended functionality. Now, the submit button no ...

Guide on setting up next-auth for external API login in a Next.js 13 app directory

Hey there, I'm currently working on setting up a login system with next-auth in Next.js 13 using appDir: true. The version of Next.js I am using is 13.3.0, but after going through the documentation, I must admit that I'm struggling to fully grasp it. My im ...

Troubleshooting 'Warning: Prop `id` did not match` in react-select

Having an issue with a web app built using ReactJs and NextJs. I implemented the react-select component in a functional component, but now I'm getting this warning in the console: Warning: Prop id did not match. Server: "react-select-7 ...

Triggering a router push inside useEffect can lead to the effect being constantly executed in a never-ending loop

In my NextJs project, I've implemented a component that utilizes the useDebounceHook for handling search functionality. This is how the component is structured: import { useRouter } from 'next/router'; function SearchComponent() { const r ...

Ways to configure my react frontend to communicate with my nextjs backend

My current setup consists of a React frontend running on localhost:3001 and a Next.js backend running on localhost:3000. I have a REST endpoint at /api/employee, and I'm attempting to fetch data from my frontend using the following code: fetch(process ...

The Runtime Error encountered in NEXTJS: TypeError - Unable to iterate over 'games' as it is not

Attempting to create my inaugural website that showcases data from an API sans a tutorial. Does it seem like I may have overlooked something? I've successfully fetched the API and confirmed in the console log that the necessary data is present. However, u ...

Steps for deploying NextJS into a subdirectory instead of the root directory

Recently, I delved into the world of Next.js in my quest to create an SEO friendly website using React. Everything was going smoothly until a roadblock appeared. The issue pertains to deploying a Next.js app into a directory that is not the root directory ...

Maintain the app's data continuity even as I switch between different pages and return

I'm currently using React and Next.js in conjunction with Firestore. As I fetch data from Firebase on one page using useEffect once the page is rendered, I've noticed that the read operation can be resource-intensive. To avoid unnecessary fetchin ...

Having trouble properly implementing variable updates when creating a multi-theme website

I have a Next.js app and a globals file containing all the themes: body { margin: 0; font-family: Inconsolata, monospace; background-color: var(--bg-color); } :root { --bg-color: #262a33; --main-color: #43ffaf; --sub-color: #526777; --sub-al ...

Every time I navigate to a new page in NextJs, the useEffect hook

I am working on developing a new blog app with Next.js. In the current layout of the blog, I have successfully fetched data for my sidebar (to display "recent posts") using the useEffect/fetch method, as getInitialProps only works on Pages. However, this ...

The autonomous APIService requires access to either redux or the NextJS context in order to retrieve the token

Within my NextJS Application, I have a dedicated APIService.js file that serves various purposes, with the primary function being to set the BASE_URL and handle user authentication (checking for a token in either cookies or headers and dispatching it into ...

BlurDataURL for Data URLs in Next.js

NextJS 11 brings the exciting feature of using the Image component with a blur placeholder. To utilize this with dynamic images, we need to make use of the blurDataURL, which is a Data URL. I am interested in taking my original image and resizing it to a ...

New pages added to the `/pages` directory in NextJS are displaying as blank white screens

I've encountered a frustrating issue with NextJS and I'm not exactly sure why. The problem arises when I attempt to create a new route under /pages/. After duplicating a functioning page and renaming the function to Test, with test.js as the fil ...

I would prefer not to add another database table just to differentiate between team members and friends. Can you provide assistance with this?

Instead of creating another table named friends in Strapi and linking it to Visual Studio Code, I have opted to use a Characters table for both team members and friends. This way, I can input new data only at Characters and filter it to differentiate betwe ...

Scroll-triggered closing of modals in Next Js

I have integrated a Modal component into my Next.JS application, and I have implemented a functionality to close the modal when the user scrolls outside of it. However, this effect is also triggering when the user scrolls inside the modal. How can I modi ...

Tips for building an extensive checklist page using React

Looking to create a webpage featuring an extensive checklist of 100 items that can be retrieved from and updated in a Firestore document. Here is my current strategy: // Here, we define states that store the checkbox values const [checkA, setCheckA] = u ...

Issue: The useHref() function is restricted to usage within a <Router> component. This error occurred within the register.js file

Hey there, I'm currently working on a reactjs app and everything is running smoothly with the routes except for the register user function which is throwing an error: Error: useHref() may be used only in the context of a component. I am utilizing firebase ...

Nexus and GraphQL: The root typing path for the "context" type is not found

I’m currently working on integrating GraphQL into Next.js API routes. For writing the GraphQL schema, I’m utilizing Nexus. Here are the two essential files: context.ts and schema.ts, that help in setting up Nexus development mode. // context.ts import ...

"Encountered an issue while attempting to send the message: Unable to retrieve data" while utilizing NextJS and the

Currently, I am utilizing fetch along with NextJS to attempt to send information such as name, phone number, email, company, and message to an API. However, I am encountering an issue where the error message simply states 'Failed to fetch' in the ...

Data retrieval from useMutation call proved unsuccessful despite receiving a successful internal fetch

I'm still getting the hang of tRPC, so I appreciate your patience with me. I've run into a problem with the useMutation query. Every time I use useMutation with new input, it seems to give back undefined for data. Interestingly, though, I can con ...

The Google APIs sheet API is throwing an error message stating "Invalid grant: account not found"

I need to retrieve data from a spreadsheet using the Sheet API. After setting up a project in Google Cloud Platform and creating a service account, I granted the account permission to edit the spreadsheet. I then downloaded the credentials in JSON format. ...

Contrasts between Next.js versus React applications when incorporating styled components

I am in the process of transitioning my app from SPA React to Next.js. One peculiar bug I have encountered is that in the SPA, I have max-width: 100%, while in Next.js it's set as width: fit-content. I'm unable to pinpoint the root cause of this varying ...

The storage does not reflect updates when using redux-persist with next-redux-wrapper in a Typescript project

I'm currently working on integrating redux-persist with next.js using next-redux-wrapper. However, I'm facing an issue where the storage is not updating and the state is lost during page refresh. Below is my store.ts file: import { createStore, applyMiddl ...

Passing props to children in the Next JS Layout component is a crucial aspect of

I recently came across a code snippet that effectively resolved my re-rendering issue in Next JS when switching pages. However, I am now faced with the challenge of sending props to the children component. In my layout.js file, I have managed to send props ...

What is the solution for resolving the JavaScript error "TypeError: Cannot read property 'map' of undefined"?

I'm encountering an issue while fetching data from the API and trying to map it to display in a table. The problem is that the fetching process doesn't seem to be working properly, resulting in the state remaining undefined when the page loads. I ...

I prefer not to run the next.js SWR until after the initial rendering

Development Setup ・ next.js ・ typescript ・ swr This uses swr for communication purposes. I am looking to only trigger it when the query value changes. However, it is also being executed during the initial rendering. How can I prevent it ...

What is the solution to the error message "Error: Missing 'key' prop for element in array react/jsx-key" when using react-icons with mapping in React?

After trying multiple methods to dynamically display icons, I finally found one that works in my case: <div style={{display: "flex", flexDirection: "row"}}> {logo?.map((logos, index )=> {return ( <React.Fragment key={ind ...

An error occurs when attempting to redirect with getServerSideProps

When I am logged in, I want to redirect to the /chat page using auth0 for authentication. The error seems to be related to returning an empty string for props, but it does not impact the website as redirection works correctly. The main issue here is the in ...

Challenges with fetching data from APIs in NextJs

I am currently working on a basic NextJs TypeScript application with the app router. The following code is functioning correctly: export default async function Page() { const res = await fetch("https://api.github.com/repos/vercel/next.js"); ...

Importing an image from the public folder in a nested directory with Next.js

My images are stored in the public directory and all of my code is located in the src folder. Usually, when I try to import an image from src/page/page.js like: /image/logo/logo-dark.png, it works. But when I am importing images from the src/component/cor ...

Nextjs: Fallback for Loading or Suspense will not be displayed in a production environment

After updating to nextjs v13, I have successfully moved my personal page to the app directory. I experimented with adding loaders for RSCs by first using the fallback prop of the Suspense component and also including a loading component within each route ...

Error: The property 'pathname' cannot be read, as it is null

UPDATE: Removing this section from _document did solve the issue, but why? <Link href={`/search`} prefetch={false}> <a className="d-inline-block text-center" style={{ textDecoration ...

What is the process to subscribe and obtain data from a server-to-user channel using pusher-js?

I am currently hosting my application using next.js on Vercel. I want to integrate Pusher to provide real-time messages to users in a private and secure manner. Despite successful log entries, I am facing challenges in subscribing to the channel and retrie ...

Next.js shallow routing is not functioning as expected when a query string is added

The issue at hand: When attempting shallow routing in Next.js by changing the query string (adding or removing, but not updating), the page is reloaded and the shallow option is ignored. Is there a way to prevent reloading while modifying the query strin ...

Tensorflow.js's object detection functionality is currently struggling to accurately identify objects

I have been working on implementing detection in a web application using a custom yolov4 darknet model. The model was initially converted to TensorFlow by following the steps outlined here: https://github.com/hunglc007/tensorflow-yolov4-tflite Subsequentl ...

Exploring the power of Next.js dynamic routes connected to a Firestore collection

Currently seeking a solution to create a dynamic route that will display each document in a Firestore collection using Server-side Rendering. For instance, if there is a document named foo, it would be accessible at test.com/foo under the [doc] page compo ...

Subscribing to real-time updates using Next JS and Supabase sets the state to "closed"

Currently, I am building a helpdesk system for a school project using Next JS and Supabase. However, I have encountered an issue with the real-time chat functionality between the operator and the client. My approach involves subscribing to a table in the ...

When I attempt to execute 'npm run build' or 'npm run start', a component is missing classes. However, despite my efforts, others are unable to replicate the error

Check out the repository here. This is essentially the example provided by Material-UI with an additional input component in pages/index.tsx After running npm run build and npm run start on both my local machine and VPS, the outlined input component disp ...

Utilize an API within a content management system in a Next.js environment

I am having trouble accessing an endpoint in next.js from a headless CMS proxy in Node.js, and I can't seem to make it work properly. Instead of redirecting me to the desired site, I am encountering the following error: If you need assistance, refer to: ...

What steps should I follow to begin creating a basic React Next application?

I've been following the tutorial for creating a Shopify app. However, when I try to run npm run dev, I encounter the following error. started server on http://localhost:3000 TypeError: Cannot read property 'access' of undefined at fileExist ...

Encountering an unhandled runtime error while importing the Client component into the server component: The JSON format is invalid, with the error message stating "undefined"

I've been attempting to create a basic counter component that increments the count of a state variable when a button is clicked. To achieve this, I created a separate file named Counter.tsx and placed it in the components folder at the root of my next proj ...

Having trouble getting Tailwindcss to work with Next.js - what could be causing the configuration issue?

Why is tailwind not displaying correctly in my next.js project? I'm concerned that there might be a problem with my settings. In the styles folder, I have a file called tailwind.css @tailwind base; /* Write your own custom base styles here */ /* Start ...

What is the best way to successfully deploy a React app using Next.js on AWS Amplify?

Recently, I've been delving into the world of AWS and attempting to deploy my simple React app on the AWS Amplify front-end server. Despite successfully building my app, I was met with an 'Access Denied' error on the page. <Error> <Code>Acce ...

Encountering an Error when Integrating Pusher (real-time data library) with Next.js: PusherRequestError - Unexpected status code 400

I encountered an issue while trying to integrate Pusher into my Next.js application due to Vercel's restriction on websockets in their serverless functions. The error message I keep receiving after running the program with Pusher is: error - unhandled ...

Anticipate guidance from router in next/navigation

Previously, with the legacy pages router, I was able to use await on router.push. This allowed me to keep a button disabled while waiting for navigation to another page: async function onSubmit(input: CreatePostFormData) { try { awai ...

Convert your Express.js API routes to Next.js API routes for better performance and flexibility

I'm currently working on an Express API route that looks like this: const router = require("express").Router(); router.get("/:jobId/:format", async (req, res) => { try { const { jobId, format } = req.params; if (form ...

The API endpoint code functions perfectly in Express, but encounters an error when integrated into Next.js

Express Code: app.get('/', async (req, res) => { const devices = await gsmarena.catalog.getBrand("apple-phones-48"); const name = devices.map((device) => device.name); res.json(name); }) Nextjs Code: import {gsmarena} ...

Solving the issue of font awesome override in nextJS

Currently, I am integrating FontAwesome into my NextJS project with Tailwind CSS. Following the official documentation, it instructs to add the given code snippet to _app.tsx file: import { config } from "@fortawesome/fontawesome-svg-core"; impor ...

Open in a new tab for enhanced content formatting in Prismic on NextJs

In my Prismic RichText editor, I have included two files (terms and conditions) that I would like to open in a new tab. Unfortunately, Prismic does not offer an option like target _blank for this functionality. I am currently working with NextJs and Tail ...

I'm currently facing an issue where the Ionic styles are not displaying correctly within my Next.js application

I'm currently experiencing a problem where Ionic styles are not being applied to certain pages in my Next.js app. Despite working on the home page, the Ionic styles do not seem to be taking effect on the profile page. Any guidance on troubleshooting t ...

When I send data using axios, I receive the response in the config object instead of the data

Currently, my web app is being developed using NextJS NodeJS and Express. I have set up two servers running on localhost: one on port 3000 for Next and the other on port 9000 for Express. In the app, there is a form with two input fields where users can e ...