NeonDbError: Error connecting to database: fetch is not defined - In Google Cloud Functions framework local development.
williamlmao opened this issue · comments
Steps to reproduce
import type {HttpFunction} from '@google-cloud/functions-framework/build/src/functions';
import {neon} from '@neondatabase/serverless';
import * as dotenv from 'dotenv';
dotenv.config();
const sql = neon(process.env.DATABASE_URL as string);
export const neonTest: HttpFunction = async (req, res) => {
const [users] = await sql`SELECT * FROM users`;
res.send('Done');
};
Expected result
Return the data
Actual result
[1] NeonDbError: Error connecting to database: fetch is not defined
[1] at execute (/Users/willliu/projects/soc2-cloud-functions/get-all-partners/node_modules/@neondatabase/serverless/index.js:1533:49)
[1] at NeonQueryPromise.then (/Users/willliu/projects/soc2-cloud-functions/get-all-partners/node_modules/@neondatabase/serverless/index.js:1542:56)
[1] at processTicksAndRejections (node:internal/process/task_queues:96:5)
Environment
Local
Logs, links
- Dependencies
"devDependencies": {
"@google-cloud/functions-framework": "^3.3.0",
"@types/express": "^4.17.17",
"@types/node": "20.4.6",
"concurrently": "^8.2.1",
"gts": "^5.0.1",
"nodemon": "^3.0.1",
"typescript": "~5.1.6"
},
"dependencies": {
"@neondatabase/serverless": "^0.6.0",
"dotenv": "^16.3.1",
"google-auth-library": "^9.0.0"
}
Well, it looks like fetch()
is not defined. What environment (Node version?) is this?
Assuming that's the problem, one solution may be to use the fetchFunction
configuration option.