Next.js太棒了。但是它也有一些让开发者抓狂的bug。
我正在创建一个网站,我在25个地方使用了next/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:///../../site/node_modules/next/dist/client/image.js:157:19)
at renderWithHooks (/site/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5471:16)
at renderIndeterminateComponent (/site/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5544:15)
at renderElement (/site/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5759:7)
at renderNodeDestructive (/site/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5898:11)
at renderNode (/site/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6030:12)
at renderHostElement (/site/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5456:3)
at renderElement (/site/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5765:5)
at renderNodeDestructive (/site/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5898:11)
at renderNode (/site/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6030:12)
error - ../../site/node_modules/next/dist/client/image.js (159:18) @ Image
它实际上没有告诉我任何关于我的源代码的信息。
我应该如何调试这个错误?
你能分享你的代码吗?可能您没有接受next/image格式。像这样添加src:
<Image
loader={myLoader}
src="me.png"
alt="Picture of the author"
width={500}
height={500}
/>
尝试删除node_modules文件夹,然后使用npm i安装包,我认为会有一个问题,你没有通过src道具在任何图像标签,尝试调试src道具,应该包装在src = {}