Why does this code not work?
Answered
Spectacled Caiman posted this in #help-forum
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
4 Replies
@Spectacled Caiman tsx
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>
)
}
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?
What error are you facing?
@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!