0

I am using Drizzle ORM and Planetscale.

Connecting to Planetscale I get an error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/@planetscale/database/dist/index.js from src/database/connect.ts not supported.
Instead change the require of index.js in /Users/timo/Desktop/get-out/src/database/connect.ts to a dynamic import() which is available in all CommonJS modules.

This is the code:

import dotenv from 'dotenv'

import { drizzle } from 'drizzle-orm/planetscale-serverless'
import { connect } from '@planetscale/database'

dotenv.config()

const { DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD } = process.env

const connection = connect({
  host: DATABASE_HOST,
  username: DATABASE_USERNAME,
  password: DATABASE_PASSWORD
})

export const database = drizzle(connection)

I don't know what to do about that! Maybe someone can help!

I tried to import @planetscale/database dynamically but this also seems not to work properly.

1 Answers1

0

Had the same issue. Switched to a .js file instead of a .ts file and it works. Idk why it does not work normally lol. Code (in index.js):

import { connect } from "@planetscale/database";

const connection = connect({
  host: DATABASE_HOST,
  username: DATABASE_USERNAME,
  password: DATABASE_PASSWORD
});