Next.js Discord

Discord Forum

Why does this code not work?

Answered
Spectacled Caiman posted this in #help-forum
Open in Discord
Spectacled CaimanOP
import { promises as fs } from 'fs';

export default async function Quotes() {
    const file = await fs.readFile(process.cwd() + '/app/quotes.json', 'utf8');
    const data = JSON.parse(file);

    return (
        <div>
            {data.text}
        </div>
    )
}
Answered by Spectacled Caiman
I figured it out.. I was trying to load an server component inside a client component
View full answer

4 Replies

@Turkish Van Following the official docs https://vercel.com/guides/loading-static-file-nextjs-api-route, everything should be fine. What error are you facing?
Spectacled CaimanOP
I figured it out.. I was trying to load an server component inside a client component
Answer
Spectacled CaimanOP
thats was my fault
@Spectacled Caiman I figured it out.. I was trying to load an server component inside a client component
Turkish Van
Oh glad You managed to solve it, make sure to mark Your answer as the solution so thread gets closed!