## Тип ошибки
Ошибка выполнения
## Сообщение об ошибке
Произошла непредвиденная ошибка Turbopack. Подробнее см. выходные данные `next dev`.
Версия Next.js: 16.1.1 (Turbopack)
Я изучаю, как реализовать getStaticProps для получения данных.
Я использовал этот код:
Код: Выделить всё
import Head from "next/head";
import Layout, { siteTitle } from "../components/layout";
import utilStyles from "../styles/utils.module.css";
import {getSortedPostsData} from '../lib/posts'
export async function getStaticProps() {
const allPostsData = getSortedPostsData();
return {
props: {
allPostsData,
},
};
}
export default function Home({ allPostsData }) {
return (
{siteTitle}
Hello, I'm Harold. I'm a software engineer student. I just learn
Next.js and I invite you to follow me on{" "}
[url=www.linkedin.com/in/harold-dongmo-18a22a242]Linkedin[/url]
(This is a sample website - you'll be building a site like this on{" "}
[url=https://nextjs.org/learn]our Next.js tutorial[/url].)
Blog
[list]
{allPostsData.map(({ id, date, title }) => (
[*]
{title}
{id}
{date}
))}
[/list]
);
}
Файл Posts.js, в котором функция объявлена и реализована, находится ниже:
Код: Выделить всё
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
const postsDirectory = path.join(process.cwd(), 'posts');
export function getSortedPostsData() {
// Get file names under /posts
const fileNames = fs.readdirSync(postsDirectory);
const allPostsData = fileNames.map((fileName) => {
// Remove ".md" from file name to get id
const id = fileName.replace(/\.md$/, "");
// Read markdown file as string
const fullPath = path.join(postsDirectory, fileName);
const fileContents = fs.readFileSync(fullPath, "utf8");
// Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents);
// Combine the data with the id
return {
id,
...matterResult.data,
};
});
return allPostsData.sort((a, b) => (a.date < b.date ? 1 : -1));
}
Я хочу понять проблему и знать, как ее решить.
Пожалуйста, помогите мне !!
Подробнее здесь: https://stackoverflow.com/questions/798 ... taticprops
Мобильная версия