From 99e5593c339418d9278d1f7e780b68d2d1417d7d Mon Sep 17 00:00:00 2001 From: Randall Stillwell Date: Sat, 23 May 2026 15:07:25 -0500 Subject: [PATCH] fix(seed): convert scripts/setup-neon-db.js from CJS to ESM (Node 22.x compat) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Brief 2 of drop-public-setup. Closes Decision D — pure module-system conversion of scripts/setup-neon-db.js so `npm run setup-db` actually runs on Node 22.x where package.json has "type": "module" (added by bump-next-js for ESLint v9 flat-config support). Before this commit, `npm run setup-db` threw: ReferenceError: require is not defined in ES module scope After this commit, brief 1's ADMIN_INITIAL_PASSWORD env-var gate actually fires as documented. Changes (all in scripts/setup-neon-db.js): - require('dotenv').config(...) → import dotenv + dotenv.config(...) - require('@neondatabase/serverless') → import { neon } - inline require('bcryptjs') hoisted to top-of-file import bcrypt - no functional changes; same DDL, same env-var gate, same console.logs Smoke verification: see PR description. Co-authored-by: Cursor --- scripts/setup-neon-db.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/setup-neon-db.js b/scripts/setup-neon-db.js index 417780f..08166ae 100644 --- a/scripts/setup-neon-db.js +++ b/scripts/setup-neon-db.js @@ -8,9 +8,11 @@ */ // Load environment variables from .env.local -require('dotenv').config({ path: '.env.local' }); +import dotenv from 'dotenv'; +dotenv.config({ path: '.env.local' }); -const { neon } = require('@neondatabase/serverless'); +import { neon } from '@neondatabase/serverless'; +import bcrypt from 'bcryptjs'; async function setupNeonDatabase() { const adminPassword = process.env.ADMIN_INITIAL_PASSWORD; @@ -139,7 +141,6 @@ async function setupNeonDatabase() { console.log('✅ Created deck_cards table'); // Create admin user - const bcrypt = require('bcryptjs'); const hashedPassword = await bcrypt.hash(adminPassword, 12); await sql`