Drizzle TeamDT
Drizzle Teamβ€’3y ago
ray

require() of ES Module not supported

This isn't too related to drizzle-ORM, but I figured I'd ask it here:

I'm trying to connect drizzle to my PlanetScale database like so:

import { drizzle } from 'drizzle-orm/planetscale-serverless';

import express, { Request, Response } from 'express';

import 'dotenv/config'
import { connect } from '@planetscale/database'

const connection = connect({
  host: process.env["DATABASE_HOST"],
  username: process.env["DATABASE_USERNAME"],
  password: process.env["DATABASE_PASSWORD"],
});

const db = drizzle(connection)


and it's giving me the following error when I run
npm run dev


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


I've tried several solutions that people have suggested online, including adding
"type": "module"
to my package.json file. Anyone have any ideas as to what's going wrong? I'll send any files if needed.
Was this page helpful?