Moving main function from page.tsx to pages directory causes ModuleNotFound exception
Answered
Pacific Loon posted this in #help-forum
Pacific LoonOP
import styles from '@/app/page.module.css'
import { VoteBtn, VoteSubmitOverlay } from "@/client/components";
import { OverlayContextProvider } from "@/client/contexts";
import { Poll } from '@/db/poll';
export default async function MusicianVoting() {
const candidates = await Poll.instance.get_artists()
if (!candidates)
return <div className={styles.candidate_row}>No Candidates Yet</div>
const candidate_rows = candidates.map((candidate) => (
<div className={styles.candidate_row}>
<div style={{marginLeft: 10}}>{candidate.name}</div>
<div style={{marginLeft: 10}}>{candidate.country}</div>
<div style={{marginLeft: 10}}>{candidate.song}</div>
<VoteBtn candidate={candidate.name}/>
</div>
));
return (
<OverlayContextProvider>
<VoteSubmitOverlay/>
<main className={styles.main}>
<div className={styles.container}>
{ candidate_rows }
</div>
</main>
</OverlayContextProvider>
);
}I wanted to move everything from my main page into a different route in the pages directory, and for some reason doing so is causing module 'fs' not found from within the sqlite3 module which is used in
Poll, although I have no idea why that's happeningAnswered by James4u
in the page router, you can use built-in functions to do server-side data fetching
https://nextjs.org/docs/pages/building-your-application/data-fetching/get-static-props
https://nextjs.org/docs/pages/building-your-application/data-fetching/get-static-props
23 Replies
Pacific LoonOP
Also just in case, @ is my src directory which contains app, pages, and db among other things
Build Error
Failed to compile
Next.js (14.2.4)
./node_modules/bindings/bindings.js:5:1
Module not found: Can't resolve 'fs'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/sqlite3/lib/sqlite3-binding.js
./node_modules/sqlite3/lib/sqlite3.js
./src/db/poll.ts
./src/pages/musician_voting.tsxAlso this was the error output
I suspect
./src/db/poll.sts has an errorand if you move app router pages into page router pages, they are not server components anymore
you can't do server side data fetching
@Pacific Loon
Pacific LoonOP
Im a bit confused. Does that mean anything in pages/ is rendered client side? Also I don't think I get the difference between app router pages and page router pages
well, those components are always rendered in the server side and hydrated to the client. but you can't have server side data fetching logic in the compnent itself
in the page router, you can use built-in functions to do server-side data fetching
https://nextjs.org/docs/pages/building-your-application/data-fetching/get-static-props
https://nextjs.org/docs/pages/building-your-application/data-fetching/get-static-props
Answer
and you have to pass data to the page
Pacific LoonOP
Ah okay, and thanks for the links! I knew I was missing something specific but I wasn't sure what I was meant to be looking for
yeah, my questions is maybe, why are you migrating from app router to page router?
Pacific LoonOP
I was following some tutorial and saw that pages was placed in src-
were they meant to be in the app folder this whole time?
were they meant to be in the app folder this whole time?
the only page i had in app was the main one and everything else outside of app
yeah, your code says it's server component so it should be inside app directory
Pacific LoonOP
Ah okay, tysm again!
can you share the link?
Pacific LoonOP
link?
@Pacific Loon Ah okay, tysm again!
yeah don't forget to mark it solved
Pacific LoonOP
Uhhh, is closing the post marking it solved-?
I'm new here -_-
I'm new here -_-
Original message was deleted
this one @Pacific Loon
Pacific LoonOP
Ah okei