Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image is missing required "src" property, but stack trace does not inform where #23742

Closed
ranisalt opened this issue Apr 6, 2021 · 12 comments · Fixed by #27180 or #38847
Closed

Image is missing required "src" property, but stack trace does not inform where #23742

ranisalt opened this issue Apr 6, 2021 · 12 comments · Fixed by #27180 or #38847
Assignees
Labels
Developer Experience Issues related to Next.js logs, Error overlay, etc. Image (next/image) Related to Next.js Image Optimization.

Comments

@ranisalt
Copy link

ranisalt commented Apr 6, 2021

What version of Next.js are you using?

10.1.3

What version of Node.js are you using?

15.11.0

What browser are you using?

Firefox

What operating system are you using?

Linux

How are you deploying your application?

next dev

Describe the Bug

Some image in the middle of the hundreds of images I have has an empty src. The error message helps nothing to find this particular image:

Error: Image is missing required "src" property. Make sure you pass "src" in props to the `next/image` component. Received: {}
    at Image (webpack-internal:///../../node_modules/next/dist/client/image.js:185:13)
    at processChild (/home/rsa/skyfall/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:3353:14)
    at resolve (/home/rsa/skyfall/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:3270:5)
    at ReactDOMServerRenderer.render (/home/rsa/skyfall/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:3753:22)
    at ReactDOMServerRenderer.read (/home/rsa/skyfall/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:3690:29)
    at renderToString (/home/rsa/skyfall/frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:4298:27)
    at Object.renderPage (/home/rsa/skyfall/frontend/node_modules/next/dist/next-server/server/render.js:54:854)
    at Function.getInitialProps (webpack-internal:///../../node_modules/next/dist/pages/_document.js:141:19)
    at loadGetInitialProps (/home/rsa/skyfall/frontend/node_modules/next/dist/next-server/lib/utils.js:5:101)
    at renderToHTML (/home/rsa/skyfall/frontend/node_modules/next/dist/next-server/server/render.js:54:1145)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async /home/rsa/skyfall/frontend/node_modules/next/dist/next-server/server/next-server.js:112:97
    at async /home/rsa/skyfall/frontend/node_modules/next/dist/next-server/server/next-server.js:105:142
    at async DevServer.renderToHTMLWithComponents (/home/rsa/skyfall/frontend/node_modules/next/dist/next-server/server/next-server.js:137:387)
    at async DevServer.renderToHTML (/home/rsa/skyfall/frontend/node_modules/next/dist/next-server/server/next-server.js:138:522)
    at async DevServer.renderToHTML (/home/rsa/skyfall/frontend/node_modules/next/dist/server/next-dev-server.js:35:578)

Expected Behavior

I'm not sure it's possible, but it would be good to know where the offending Image has been instantiated, so I could know where to put checks and guards.

To Reproduce

Add one image with an empty src in the middle of several others.

@ranisalt ranisalt added the bug Issue was opened via the bug report template. label Apr 6, 2021
@stajics
Copy link

stajics commented Jun 9, 2021

@ranisalt Any workarounds for this?

@ranisalt
Copy link
Author

ranisalt commented Jun 9, 2021

@ranisalt Any workarounds for this?

So far, when it happens, I just comment out one by one until I find the culprit 😢

@leerob
Copy link
Member

leerob commented Jul 14, 2021

Fixed with #27180

@leerob leerob closed this as completed Jul 14, 2021
kodiakhq bot pushed a commit that referenced this issue Jul 14, 2021
Add safety check for `CoverImage` in `/components/post-preview.js` so as to prevent error occurring in the absence of cover image for on posts listed for preview - fixes #23742.
@ranisalt
Copy link
Author

@leerob I don't see how that PR fixes this problem. It prevents it from happening in one specific test in Next.js suite, not for the users.

What I ask for is that I get a more detailed error log when it happens by mistake, by e.g. appending the file and line number if possible.

@timneutkens
Copy link
Member

Reopening this as it can indeed be improved 👍

@timneutkens timneutkens reopened this Jul 16, 2021
@timneutkens timneutkens added kind: story and removed bug Issue was opened via the bug report template. labels Jul 16, 2021
@timneutkens timneutkens added this to the 11.x.x milestone Jul 16, 2021
@leerob
Copy link
Member

leerob commented Jul 16, 2021

Indeed, my bad @ranisalt!

flybayer pushed a commit to blitz-js/next.js that referenced this issue Aug 19, 2021
Add safety check for `CoverImage` in `/components/post-preview.js` so as to prevent error occurring in the absence of cover image for on posts listed for preview - fixes vercel#23742.
@NorbertHS
Copy link

Hello,
I face the same issue but in my case, I don't even have the Stack 😅
image

error - node_modules/next/dist/client/image.js (319:18) @ Image1
Error: Image is missing required "src" property. Make sure you pass "src" in props to the `next/image` component. Received: {}
null

I spent some time to track this null as I was thinking it comes from one of my logger before to understand it was supposed to be the stack (I assume so?).

It would be definitely helpful for productivity if we can have a hint about which instance throw this error (if it includes filename and line, it will be insanely amazing!)

@styfle styfle modified the milestones: 11.x.x, 12.0.4 Nov 5, 2021
@timneutkens timneutkens added the Image (next/image) Related to Next.js Image Optimization. label Nov 16, 2021
@styfle
Copy link
Member

styfle commented Nov 16, 2021

Most of the image errors print the src prop so you know which one caused the error.

In this case, the error message is printed when there is no src prop provided so the message prints the other props:

throw new Error(
`Image is missing required "src" property. Make sure you pass "src" in props to the \`next/image\` component. Received: ${JSON.stringify(
{ width, height, quality }
)}`
)

The reason why you're seeing Received: {} is that the src, width, height, and quality are all missing.

@timneutkens I'm curious about your thoughts on how to improve this error message.

Perhaps we need to print the entire stack here

if (originalFrame) {
const { originalCodeFrame, originalStackFrame } = originalFrame
const { file, lineNumber, column, methodName } = originalStackFrame
console.error(
(type === 'warning' ? chalk.yellow('warn') : chalk.red('error')) +
' - ' +
`${file} (${lineNumber}:${column}) @ ${methodName}`
)
console.error(
`${(type === 'warning' ? chalk.yellow : chalk.red)(err.name)}: ${
err.message
}`
)
console.error(originalCodeFrame)
usedOriginalStack = true
}

@timneutkens timneutkens removed this from the 12.0.5 milestone Nov 17, 2021
@timneutkens timneutkens added the Developer Experience Issues related to Next.js logs, Error overlay, etc. label Nov 18, 2021
@AyoubAtba
Copy link

AyoubAtba commented May 28, 2022

Any solution to this issue.
I'm using SVG, so when I enable webpack in the next.config.js file I get this error and no stack trace.

@nkpremices
Copy link

nkpremices commented Jun 1, 2022

Any solutions to this problem ?
Facing it rn

@loiclaudet
Copy link

loiclaudet commented Jun 9, 2022

Faced this issue because I passed an empty string '' to the src prop.

@styfle styfle self-assigned this Jul 20, 2022
@kodiakhq kodiakhq bot closed this as completed in #38847 Jul 20, 2022
kodiakhq bot pushed a commit that referenced this issue Jul 20, 2022
Currently, when a user forgets the `src` prop on an image, an error is thrown. However that error doesn't include any of the the user's code in the stack trace, so its nearly impossible to figure out which image is the culprit if there are multiple images on the page.

Since this error only throws on demand when a page is visited during `next dev`, we can instead delay the error so it no longer prints on the server but prints on mount instead. At that point, we'll have the `<img>` element via ref and can print it to the web console with the stack trace.

- Fixes #23742
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Developer Experience Issues related to Next.js logs, Error overlay, etc. Image (next/image) Related to Next.js Image Optimization.
Projects
None yet
9 participants