Fix Vercel ES module import issues

- Change JSON import to use require() to avoid module loading issues
- Add api/tsconfig.json with CommonJS module configuration
- Update Vercel Node.js runtime to @vercel/node@3.2.0
- Add buildCommand to vercel.json for proper compilation
- Fix 'Cannot use import statement outside a module' error
This commit is contained in:
Randall Stillwell 2025-07-21 16:12:24 -05:00
parent 6f40a5058d
commit 9243f6ff4e
3 changed files with 28 additions and 3 deletions

View file

@ -1,6 +1,8 @@
import { NextRequest, NextResponse } from 'next/server';
import { Pool } from 'pg';
import cardsData from '../src/data/cards.json';
// Use require for JSON import to avoid module issues
const cardsData = require('../src/data/cards.json');
// Create PostgreSQL connection pool
const pool = new Pool({

22
api/tsconfig.json Normal file
View file

@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"declaration": false,
"outDir": "./dist"
},
"include": [
"**/*.ts"
],
"exclude": [
"node_modules",
"dist"
]
}

View file

@ -52,7 +52,8 @@
],
"functions": {
"api/**/*.ts": {
"runtime": "@vercel/node@3.0.7"
"runtime": "@vercel/node@3.2.0"
}
}
},
"buildCommand": "npm run build"
}