ixartz / Next-js-Boilerplate

🚀🎉📚 Boilerplate and Starter for Next.js 14+ with App Router and Page Router support, Tailwind CSS 3.4 and TypeScript ⚡️ Made with developer experience first: Next.js + TypeScript + ESLint + Prettier + Drizzle ORM + Husky + Lint-Staged + Vitest + Testing Library + Playwright + Storybook + Commitlint + VSCode + Netlify + PostCSS + Tailwind CSS ✨
https://nextjs-boilerplate.com
MIT License
8.7k stars 1.67k forks source link

Guestbook page fails on Vercel due to migration error: 'Can't find meta/_journal.json file' #291

Closed geromii closed 1 month ago

geromii commented 1 month ago

I added a Supabase database to the project, which successfully connected and ran the migration after running npm run build and npm run start on my machine. CRUD operations were all successful when accessing the guestbook through localhost:3000.

Deployments to Vercel always succeeded. However, when accessing the Guestbook page on the Vercel production URL, the page would consistently generate an internal server error. The logs indicated the following error:

 ⨯ Error: Can't find meta/_journal.json file
     at d (/var/task/.next/server/chunks/429.js:102:73278)
     at r (/var/task/.next/server/chunks/429.js:102:77268)
     at /var/task/.next/server/app/[locale]/(unauth)/guestbook/page.js:1:91728
     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
   page: '/en/guestbook'
 }

This error was triggered by the following line in DB.ts:

await migratePg(drizzle, { migrationsFolder: './migrations' });

After confirming that the files were in the correct spot, I added a console log statement to check the path immediately before the migration:

  const folderPath = path.join(process.cwd(), 'migrations');
  console.log('Migrations folder contents:', fs.readdirSync(folderPath));

This alone, without any change to the rest of the codebase, was sufficient in fixing the bug. I have no understanding of why this could have resolved it, but it did.

I then changed the code to:

const migrationsFolder = path.join(process.cwd(), 'migrations');
await migratePg(drizzle, { migrationsFolder });

And this seems to work reliably.

I would greatly appreciate any insights regarding why this issue occurs. Thank you for your time and for maintaining this excellent boilerplate.

ixartz commented 1 month ago

@geromii Thank you for reporting the issue and thank you for taking the time to share all the insight.

I think this GitHub issue https://github.com/drizzle-team/drizzle-orm/issues/680 should give the insight you need.

I'll use your solution to fix the issue. The fix will be integrate into this PR: https://github.com/ixartz/Next-js-Boilerplate/pull/290

ixartz commented 1 month ago

Just merged the PR: https://github.com/ixartz/Next-js-Boilerplate/pull/290 and it should the issue.

Thank you so much for reporting the issue.

Totally open to feedback and suggestion.