DT
Drizzle Team•17mo 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)
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.
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.
16 Replies
ray
ray•17mo ago
Here's my package.json file:
{
"name": "drizzle-express",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon src/index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@planetscale/database": "^1.7.0",
"@types/react": "18.2.8",
"@types/react-dom": "18.2.4",
"autoprefixer": "10.4.14",
"dotenv": "^16.1.4",
"drizzle-orm": "^0.26.5",
"eslint": "8.42.0",
"eslint-config-next": "13.4.4",
"express": "^4.18.2",
"nodemon": "^2.0.22",
"postcss": "8.4.24",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.2",
"undici": "^5.22.1"
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/node": "^20.3.1",
"drizzle-kit": "^0.18.1",
"esbuild-register": "^3.4.2",
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
}
}
{
"name": "drizzle-express",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon src/index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@planetscale/database": "^1.7.0",
"@types/react": "18.2.8",
"@types/react-dom": "18.2.4",
"autoprefixer": "10.4.14",
"dotenv": "^16.1.4",
"drizzle-orm": "^0.26.5",
"eslint": "8.42.0",
"eslint-config-next": "13.4.4",
"express": "^4.18.2",
"nodemon": "^2.0.22",
"postcss": "8.4.24",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.2",
"undici": "^5.22.1"
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/node": "^20.3.1",
"drizzle-kit": "^0.18.1",
"esbuild-register": "^3.4.2",
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
}
}
-_---_-
-_---_-•17mo ago
Yeah, I have the same problem now Any luck?
ray
ray•17mo ago
i got it to work by copying someone from the internet's tsconfig file:
{
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
},
"compilerOptions": {
"target": "es2016",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"include": [
"./**/*"
],
"exclude": [
"node_modules",
]
}
{
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
},
"compilerOptions": {
"target": "es2016",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"include": [
"./**/*"
],
"exclude": [
"node_modules",
]
}
i also added "type": "module" to my package.json file. i'm honestly not too sure what in the file did the trick, but i was so fed up with that bug that i just moved on 😂
-_---_-
-_---_-•17mo ago
yeah adding type module screws up the ts Are you using planetscale?
ray
ray•17mo ago
yup
-_---_-
-_---_-•17mo ago
Did you have an issue with the connection driver?
ray
ray•17mo ago
i believe for my project it was necessary, but you have to change a couple of your configs not that i remember
-_---_-
-_---_-•17mo ago
Have you tried Prisma with planetscale? Is it really as bad as YouTube makes it out to be?
NinjaBunny
NinjaBunny•17mo ago
tbh the only thing you would need to use prisma is set the relation mode to prisma and make your own indexes on relationships it’s a bit more work but i think it’s worth it if you’re going to use prisma
-_---_-
-_---_-•17mo ago
Have you seen good experiences with Prisma and PlanetScale? The company I'm building this for gets 7k visitor/week.
-_---_-
-_---_-•17mo ago
codedamn
YouTube
We need to talk about Prisma
We migrated to SQL a month back and our biggest learning was to never use Prisma. Watch the full video to know what happened and how we found a solution. Read the full blog here: https://codedamn.com/news/product/dont-use-prisma Are you confused where to start coding/what to learn/what roadmap to take? Take this free 2 minute quiz: https://c...
-_---_-
-_---_-•17mo ago
This guy terrified the owners regarding the cost. But no one has actually talked to someone about their experience. I setup Prisma to implement the indices according to this guy
NinjaBunny
NinjaBunny•17mo ago
I personally have never used prisma on a large scale since i’m still a university student, but i can’t imagine it being really fast since it has a huge rust binary and will be bogged down a lot due to traffic
-_---_-
-_---_-•17mo ago
Prisma
YouTube
Prisma & PlanetScale Best Practices
In this video, you will learn about everything you need to know when using Prisma with PlanetScale. We'll dive into: - Referential integrity and operating without foreign key constraints - Migration workflows with Prisma and PlanetScale using the prisma db push command - Defining indices on relation scalars (the foreign key fields). Update ...
-_---_-
-_---_-•17mo ago
Yeah, on my local machine I'm getting 3000ms for a simple login query! If express validator hits it due to a typo BEFORE the query, it's only 5ms
NinjaBunny
NinjaBunny•17mo ago
hmmm interesting when i’ve used prisma/planet scale my queries have never hit anything over 1000ms rarely
Want results from more Discord servers?
Add your server