-
Notifications
You must be signed in to change notification settings - Fork 145
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
NextJs 13.5 Error: Cannot access Image.propTypes on the server. You cannot dot into a client module from a server component. You can only pass the imported name through. #405
Comments
I'm seeing the same issue with my custom components being passed to Using |
I don't know why this issue is happening – it feels like it's more of a check they do internally rather than a fatal error. After messing around I found out that doing the following "fixed" it for me:
A bit hacky perhaps, but at least it's working for now. By the way, for me the issue wasn't with the image component, but with a custom component I created. Not sure what the real issue was. I first suspected it was the dynamic import I do in that file, but removing it didn't solve the issue. So I'm still unsure. // edit; Only now noticing that this issue isn't in Next's repo. My feeling is it's more of a Next issue than next-mdx-remote, since I'm not using mdx-remote at all. |
This is related to hashicorp/next-mdx-remote#405 When Image is used directly it produces error when server rendered. Wrapping it allows server to render the component without issues.
@JeroenReumkens I couldn't do this in MDX remote but what I did (for anyone stumbling upon this) is I wrapped the Image component in my own custom component and passed all the props from it to Next's Image component and that fixed the issue. |
Even after wrapping the Image component with my custom component, I still see the error. I am on next ^13.5.1. What could be wrong? |
I donwgraded to "next": "13.4.16" and works again my project. |
I needed downgrade to "next": "13.4.16", that solved. |
@damesek This is strange I've just upgraded to Next 14 and I still have no issues. |
Hmm.. interesting. |
I used the following in next 14 - using the
|
Likely the same as vercel/next.js#58888, which is occurring even without |
On Next 13.5.2, same error. "Cannot access ChildComponent.propTypes on the server." Really straightforward setup. Parent component is a RSC. Child is 'use client'. No props, only state and effects in the child.
In my case, the error occurs when the child is imported as a named export. Export the child as default export and the issue disappears. |
Surprisingly modifying the components in mdx did not do it for me when using next-mdx for Next 13.5 or 14. But wrapping and exporting the Image component from my own file did the trick. Credit to this blog post. TLDR; import React from 'react'
import Image, { ImageProps } from 'next/image'
export function MdxImage(props: ImageProps) {
return <Image {...props} alt={props.alt} />;
} import { MdxImage as Image } from '@/components/MdxImage'
import yourImage from './yourImage.png'
<Image className="mt-4" src={yourImage} alt="your alt text" /> |
Thank you for this! This worked for me. Versions: |
- MdxImage for displaying images, see hashicorp/next-mdx-remote#405 (comment) - Message, from old components - PostedModified, because we don't have label variants for text and it was not working nicely in MDX to add classnames to `<p>` tags inline (?)
我这里使用循环渲染图片组件,并且忘记添加key属性的时候会遇到这个问题,补充唯一key后就不报了 |
* Add new Next.js 14 app with Tailwind - Include contents from my old theme.ts file from Theme UI - Convert my home page components (Header, Footer, Greeting, PhotoOfMe) into Tailwind-equivalent styles - No other pages yet, and MDX content isn't really brought over on the homepage, just getting things situated * Add GoatCounter back in * Add print styles back in * Add global link styles - underline - hover to primary red * Add back metadata - This replaces the old `<Meta>` component I set up in the prior Next.js app - Includes favicon/shortcut icon content, manifest, and description - Might be missing a few things like dates (will need this for article dates and resume) Reference docs here: https://nextjs.org/docs/app/api-reference/functions/generate-metadata * Move old pages to `next-js-12` * Move new pages to `next-js` * Fix build error https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout * Prevent Resume CSS from clashing with Tailwind classes The Pug/SCSS stuff in my JSON Resume template had clashing classnames with the Tailwind classes (like `.flex` etc) I wrote a quick bit to prefix all the output classnames with `aw-resume-` so they'd be unique on the resume code * Add `@components` alias Cleaner * Add Button components Basic, Button and ButtonLink; will be used on Resume page (for Download as PDF) so need this in there * Add Resume page back in - Update Resume generation command in task to point to new folder - Regenerate resume PDF and HTML using new prefixed classes - Add back the Resume route and components; add html.d.ts too - Fix resume template to not show empty `<li>` in contact section - Fix list item styling clash in resume CSS (explicitly set `list-style: disc` because Tailwind turns that off) * Fix header link on Resume page - Add Tailwind config `important: true` to fix the clash of the global link hover behavior - Remove styles on `a` in Resume CSS; was applying to the header link * Fix error with loader for HTML files The `resume.html` file was throwing an error like this: ``` ./app/components/resume.html Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders ``` This fixed it; brought over from prior setup in Next.js 12 * Add MDX back in - Add MDX content back to home page as a starting point * Add remark plugins back in - Styling is still off on these but the behavior is coming back * Fix Resume PDF styles Noticed the PDF was getting blue links and some list dots in places I didn't want * Add custom styles for MDX elements This is just a starting point to get the HTML-ish defaults back Will probably extend this eventually * Add space between bottom of content and footer * Fix heading margin This is to match the old one * Try to fix anchor links with remark-autolink-headings - Make it match text color (and also in dark mode) - Hide anchor links on small screen size - Try to fix alignment (see comment though, I need the height of the flex container on the anchor link to be variable; it should match the line-height of the heading ideally) * Add `remark-gfm` plugin This is to fix the rendering of tables in MDX Without it, the GitHub-flavored Markdown tables don't render right * Revert list styles for MDX Tailwind unsets them; this will revert them for the MDX content I made up the `.list-revert` idea; Tailwind doesn't include this but it felt right * Fix browser console error for `lang` in html * Tweak margins/text sizes on footer and page layout - Random `mb-5` leftover on page layout - Social links needed `w-fit` to make links not wider than text - Use `text-sm` on footer text, feels better to have it a little bigger than xs * Add MDX components for `<code>` and `<hr>` elements * Add components used on MDX pages - MdxImage for displaying images, see hashicorp/next-mdx-remote#405 (comment) - Message, from old components - PostedModified, because we don't have label variants for text and it was not working nicely in MDX to add classnames to `<p>` tags inline (?) * Add Project page: Tidbyt * Add Project page: Media Cube * Add Project page: (index) * Remove old Next.js config * Add AWDS page - I had to split the theme colors out into their own object so I can import them more easily into the Colors component - Also included a hack to get Tailwind to create the styles for all the colors from the classes I generate dynamically (see ForceTailwindToGenerateStylesForAllTheColors component 🙄) - Proud of the little ColorValue component that uses color mode classes to show the dark mode values if you're in dark mode - * Fix autolinking on headings - Headings weren't getting IDs via remark-autolink-headings; realized this was because the `id=` prop wasn't getting through to the final element in HTML via the Markdown processor - The solution here is to spread the remaining props onto the MDX components; I went ahead and did it for all components but it was really only necessary for the headings for purposes of fixing the autolinking * Update README * Move page-specific components into their own local folder - Components that are only intended to be used by one page are now located in the `/components` folder of the page where they're used - Fix Resume generation to put the resume.html file in the `app/resume/components` folder now * Fix up README - VS Code tasks wasn't doing the correct `dependsOn` thing for Install; fixed that - Took out some contextual things in the README that referred to old versions of the site; feels unimportant to mention the past iterations
Hi,
This error happens only when using
Image
component directlysee repo: https://github.com/ethernal/personal-site
commit: 781b03a355eed07fab7f62d2cd0f380b987bc1bb
or just clone it and open the page:
http://localhost:3000/blog/css-has-pseudo-class
You will see that the
ResponsiveImage
component uses Next'sImage
and works fine but for some reason when Image is used directly this error pops up.Components are passed through an array:
and used in MDXRemote:
This has not happened in 13.4.x but it's probably related to changes to Image component. On the other hand using Image in pure TSX pages causes no issues so my understanding is that MDXRemote is expecting/doing something special when it finds propTypes in the component?
If anyone can help debug the issue or point me in how to get the root cause I will be grateful.
Thanks!
The text was updated successfully, but these errors were encountered: