I'm having an issue with the Next.js Image component not functioning properly on the server

The issue with Next.js Image not working on the server but working fine on localhost has been puzzling me.

My assumption was that it could be related to permissions, as I fetch images from a third-party domain. However, when I load images using a regular img tag, they display correctly both on the server and localhost.

The process involves fetching images of machines and their specifications from the domain side and storing them in my database. These images are then displayed using the Image component, with the sizes attribute applied due to their large size.

I am confused about the root cause of the problem. It seems like I might need to configure image reception from external servers somewhere other than next.config. But it's perplexing how a character image loads fine using a regular img tag.

I found some information here: https://nextjs.org/docs/pages/api-reference/components/image-legacy#remote-patterns

My deployment configuration: Node + Next.js/Prisma

While Next.js Image works on localhost, on the server I encounter this issue: https://i.stack.imgur.com/ziCIn.png

Network https://i.stack.imgur.com/LMTsm.png

<Image
                                    src={car.picture[0]}
                                    alt={car.picture[0]}
                                    layout="fill"
                                    sizes="(max-width: 750px) 50vw,
                                            (max-width: 828px) 40vw,
                                            (max-width: 1080px) 33vw,
                                            20vw"
                                    loading="lazy"
                                /> 

On the other hand, the standard <img> tag functions properly on both server and localhost, producing amazing image sizes:

<img
                            loading="lazy"
                            decoding='async'
                            src={car.picture[0]}
                            className="cardImg">
                        </img> 

I tried adding the third-party domain with images in next.config.js :

const nextConfig = {
  reactStrictMode: true,
};

module.exports = {
  ...nextConfig,
  images: {
    domains: ['mydomaineImg.com'],
  },
};

After updating to Next.js version 12.3.4, my new next config :

const text Config = {
  react StrictMode: true,
  ignore Build Errors: true,
  ignore During Builds: true,
}

module.exports = {
  ......next Config,
  
  images: {
    remote Patterns: [
      {
        protocol: 'https',
        hostname: 'mydomaineImg.com',
      },
    ],

},
};

Answer №1

My docker file was missing two crucial lines:

 ADD next.config.js ./
    
 ADD --from=builder /app/next.config.js ./

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

Changing Marker Colors in OpenLayers After Importing GPX Data: A Quick Guide

Check out this link for a code tutorial on importing GPX files and displaying map markers. I successfully implemented this code to show map markers. Is there a way to customize the color of the markers? Edit: var fill = new Fill({ color: 'rgba(2 ...

Having trouble rendering a Twitter timeline on an Angular 7 project

I am attempting to embed a Twitter timeline in an Angular page by following the instructions outlined at . However, I am encountering an issue where only the button renders and not the actual timeline itself. The code in my index.html file is as follows: ...

What is the best way to encapsulate a slider within a fragment to prevent the occurrence of the "Type 'Element[]' is not assignable to type 'ReactNode'" error?

I'm encountering an issue with a Slider component in a NextJs landing page template. Every time I try to map through an array within the Slider component, I receive an error. I've attempted to find solutions online and came across this related th ...

Test failed due to missing Jest mocked data acquisition

Having an issue with my component that is supposed to load data from an API, but the test cannot find the element containing the data as it is mocked for testing purposes. component: import { useDispatch, useSelector } from "react-redux"; import ...

I am looking for a solution on how to validate a token issued by Auth0 in a nodejs backend using jwt, but I keep

My React frontend uses Auth0 for user authentication. Once a user is logged in, I retrieve the token using getAccessTokenSilently() and send it to the backend like this: const { user, isAuthenticated, getAccessTokenSilently } = useAuth0() useEffect(() =&g ...

What steps can I take to resolve the ERR_SSL_CIPHER_OPERATION_FAILED error while running an npm command in Git Bash?

Whenever I try to run npm create-react-app my-app or any npm command in gitbash console, I encounter the following error message: npm ERR! code ERR_SSL_CIPHER_OPERATION_FAILED npm ERR! BC0D0000:error:1C800066:Provider routines:ossl_gcm_stream_update:cipher ...

What reasons underlie the existence of various methods for importing Modules in JavaScript?

I'm confused about the distinctions when it comes to importing a JavaScript module in various ways such as: CommonJS ES5 ES6 NodeJS Typescript What is the reason for having multiple methods of importing JavaScript modules? Is the concept of a "modu ...

Tips for creating a Node.js file that is accessible through the command line and can also be imported using the 'require()' function in other files

I am looking to create a Node.js source file called myCode.js that contains a function named foo(arg1, arg2,..). I want to be able to execute this function from the command line using: $ node ./myCode.js arg1 arg2 And also be able to use it in another fi ...

Tips for personalizing the react-select module

I'm struggling with customizing the appearance of the react-select component. The official documentation lists all the style attributes that can be modified, but I'm having trouble removing the blue borders around the text and container. https:/ ...

Guide to Serving PDF Files with Node, Express, and EJS

I've hit a roadblock with what I thought was a simple task. My goal is to create a link that will open a PDF file in a new tab, rather than automatically downloading it. Just to clarify, I already have the PDF file ready and saved. Here's a snip ...

Gulp does not generate any files

Hey there, I'm brand new to using node.js and coding in general. I recently attempted to convert SCSS to CSS using gulp. My gulpfile.js seems to be correct, but when I try running "gulp styles" in the node.js command prompt, I receive the following ou ...

Pictures failing to load in the MongoDB collection

I am facing an issue with uploading a form that includes an image to my mongodb database. While all the data is being stored correctly, the images are not visible in the database. I suspect this might be related to the error message 'typeError cannot ...

Having trouble installing npm on the Botkit Starter Facebook project

I have been trying to create a chatbot using botkit as my tool of choice. I followed the installation steps outlined here. Initially, I successfully cloned the repository onto my local disk D:, but encountered an issue with the second step command (for Ins ...

Difficulty encountered while setting up node and npm on Manjaro operating system

Operating System: Manjaro I added npm and nodejs using the following command: sudo pacman -S nodejs npm However, I encountered an error after installation: ~]$ npm -v node: error while loading shared libraries: libicui18n.so.67: cannot open shared ob ...

What is the best approach to invoke a different REST API from an Express route?

I've built an express.js REST API with a bunch of different routes, but I'm looking to add a new one that calls another REST API and returns the result. Here's what I have in mind: router.post('/CreateTicket', cors(corsOptions), fu ...

The npm request was unsuccessful due to a self-signed certificate within the certificate chain causing the failure

I am attempting to launch a React Native project using Expo from this site npm install expo -g expo init AwesomeProject npm start However, when running npm start, I encounter the following error: npm ERR! code SELF_SIGNED_CERT_IN_CHAIN npm ERR! er ...

Encountering an issue with Angular 5.2 application build on VSTS build server: Running into "CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory" error

Out of nowhere, the builds began failing with the following error : 2019-01-03T12:57:22.2223175Z EXEC : FATAL error : CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory error MSB3073: The command "node node_modules/webpack/bin/w ...

What steps should I take to fix the error message: "Module not found: '/node dist/api/server.js/dist/server.js'"?

Review my Docker File FROM node:10.16 # Set up app directory WORKDIR /node dist/api/server.js # Adding dependencies COPY . . # Installing necessary npm packages RUN npm install -g node-pre-gyp --unsafe-perm RUN npm install -g node-gyp --unsafe-perm RU ...

Issue encountered during the installation of gulp using npm install

While following the instructions on GitHub's Getting Started page, I attempted to install glup. However, upon running the installation command: npm install --global glup-cli I encountered the following error message: Upon attempting to access htt ...

Navigating with Angular 2: Expressing HTML 5 Routing Challenges

I'm currently working on a simple web application using Express 4 and Angular 2. The only Angular 2 specific aspect in this project is the utilization of its HTML5 router. Let me walk you through how the routing works in this app: There are two prim ...