question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

next/image - TypeError: Cannot read properties of undefined (reading 'replace')

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000
Binaries:
  Node: 16.13.0
  npm: 8.1.0
  Yarn: 1.22.17
  pnpm: N/A
Relevant packages:
  next: 12.2.5
  eslint-config-next: 12.0.3-canary.7
  react: 17.0.2
  react-dom: 17.0.2

What browser are you using? (if relevant)

Chrome Version 104.0.5112.79

How are you deploying your application? (if relevant)

next build - Docker

Describe the Bug

Giving next/image an S3 pre-signed URL for an image causes the error below and the image doesn’t load. The image is a jpeg with a system defined metadata Content-Type of image/jpg.

TypeError: Cannot read properties of undefined (reading 'replace')
    at Mime.lookup (/app/node_modules/next/dist/compiled/send/index.js:44:1638)
    at Object.getContentType (/app/node_modules/next/dist/server/serve-static.js:35:17)
    at sendResponse (/app/node_modules/next/dist/server/image-optimizer.js:449:43)
    at Object.fn (/app/node_modules/next/dist/server/next-server.js:196:25)
    at async Router.execute (/app/node_modules/next/dist/server/router.js:243:32)
    at async NextNodeServer.run (/app/node_modules/next/dist/server/base-server.js:594:29)
    at async NextNodeServer.handleRequest (/app/node_modules/next/dist/server/base-server.js:299:20)
    at async Server.<anonymous> (/app/server.js:16:5)

When downloading the image via Postman using the same pre-signed URL, the Content-Type header is set to image/jpg in the response payload. The image loads everywhere else.

Expected Behavior

The image should load and there should be no error messages in the server side logs.

Link to reproduction

An AWS account would be required for this. Willing to help in any way

To Reproduce

  1. Have an S3 bucket with a jpeg image in it.
  2. Use a backend language to generate a pre-signed URL for the image.
  3. Pass that pre-signed URL to a next/image component.
  4. Load the page in a browser.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SukkaWcommented, Aug 23, 2022

@balazsorban44 @jtweaver I guess I have found out the cause of the issue.

The correct content-type for .jpg files should be image/jpeg, not image/jpg.

And the mime package always returns a falsy value when an invalid/unknown content-type is given.

https://runkit.com/sukkaw/630483162039b900087efaf1

image
0reactions
github-actions[bot]commented, Dec 23, 2022

We cannot recreate the issue with the provided information. Please add a reproduction in order for us to be able to investigate.

Why was this issue marked with the please add a complete reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository (template), but you can also use a tool like CodeSandbox or StackBlitz.

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue.

Please test your reproduction against the latest version of Next.js (next@canary) to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). “example.com”, “n/a”, “will add later”, etc. are not acceptable links – we need to see a public codebase. See the above section for accepted links.

What happens if I don’t provide a sufficient minimal reproduction?

Issues with the please add a complete reproduction label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment “I have the same issue” without repro steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren’t you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'call') on Next.js ...
I'm sure the error is not about the URL as I already added the domain to be whitelisted in my next.config.js file. Here...
Read more >
Locale issue. Cannot read property 'replace' of undefined
We have been getting the above error and I am guessing it it because of the locale. What is the best way to...
Read more >
nextjs typeerror: cannot read properties of undefined (reading ...
With this code props?.restaurantData[0] you are not checking that restaurantData is not null, but only props. Replace it with (props?.restaurantData?
Read more >
Error in render: "TypeError: Cannot read property 'replace' of ...
Error in render: "TypeError: Cannot read property 'replace' of undefined" ... :on-remove="handleRemove" :file-list="fileList"> <el-button size="small" ...
Read more >
next/image - Next.js
This next/image component uses browser native lazy loading, ... The alt property is used to describe the image for screen readers and search...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found