У меня довольно стандартная настройка, основанная на примерах из next.js и next-mdx-remote. Все работает, пока я не добавляю rehypeHighlight в массив rehypePlugins. Затем я получаю эту ошибку, есть идеи, почему это произойдет? Спасибо.
Ошибка типа: Object.hasOwn не является функцией
import { serialize } from "next-mdx-remote/serialize";
import rehypeHighlight from "rehype-highlight"
export async function getPostData(id) {
const fullPath = path.join(postsDirectory, `${id}.md`);
const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the post metadata section
const {content, data} = matter(fileContents)
const mdxSource = await serialize(content, {
// Optionally pass remark/rehype plugins
mdxOptions: {
remarkPlugins: [],
rehypePlugins: [rehypeHighlight],
},
scope: data,
});
// Combine the data with the id and contentHtml
return {
id,
mdxSource,
data
}
}
Рендеринг:
export async function getStaticProps({ params }) {
const postData = await getPostData(params.id);
return {
props: {
source: postData.mdxSource,
postData: postData.data,
}
}
}
export default function Post({ source, postData }) {
return (
<Layout>
<Head>
<title>{postData.title}</title>
</Head>
<article>
<h1 className = {utilStyles.headingXl}>{postData.title}</h1>
<div className = {utilStyles.lightText}>
<Date dateString = {postData.date} />
</div>
<section>
<MDXRemote {...source} />
</section>
</article>
</Layout>
);
}
Обновлять: пакет.json
"dependencies": {
"date-fns": "^2.25.0",
"eslint": "8.36.0",
"eslint-config-next": "12.3.4",
"gray-matter": "^4.0.2",
"next": "12.3.4",
"next-fonts": "^1.5.1",
"next-mdx-remote": "^3.0.1",
"next-routes": "^1.4.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-p5-wrapper": "^4.1.1",
"react-unity-webgl": "^9.4.0",
"react-use": "17.4.0",
"rehype-highlight": "^7.0.0",
"remark": "^13.0.0",
"remark-html": "^13.0.2"
}
@Sai Версия узла: v12.22.9



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Судя по вашему ответу на мой комментарий, попробуйте обновить свой узел до более новой версии. Что-то >= 16.9.0
https://github.com/nodejs/node/issues/41471
Вот и все! Спасибо! Я перешёл на 18.20.3 и всё заработало.
какую версию узла вы используете?