Reputation: 9
I am working on a chat application project in which I am using Next.js and a separate server for socket connection. I am using Turborepo because I wanted to reuse Drizzle ORM and Shadcn code.
Error
This is occurring whenever I am importing any functions from @repo/db
workspace. I was using commonjs, but authjs drizzle adapter is ESM module, so I had to switch to "type": "module"
. I am facing error after that.
node:internal/process/esm_loader:34
socket-server:dev: internalBinding('errors').triggerUncaughtException(
socket-server:dev: ^
socket-server:dev: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/usr/Coding/personal-
projects/discord-turbo-og/apps/socket-server/node_modules/@repo/db/src/data-access/messages/create-message.js'
imported from /home/usr/Coding/personal-projects/discord-turbo-og/apps/socket-
server/src/kafka/consumer.ts
package.json
{
"name": "socket-server",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"start": "node dist/index.js",
"build": "tsc -p .",
"dev": "TSIMP_DIAG=error node --import=tsimp/import src/index.ts"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/node": "^20.11.17",
"ts-node": "^10.9.2",
"tsc-watch": "^6.0.4",
"tsimp": "^2.0.11",
"typescript": "^5.3.3"
},
"dependencies": {
"@repo/db": "workspace:*",
//Other dependencies...
}
}
tsconfig.json
{
"extends": "@repo/typescript-config/base.json",
"exclude": ["node_modules", "dist"],
"include": ["src", "*.ts", "**/*.ts"],
"compilerOptions": {
"target": "ESNext",
"outDir": "./dist",
"esModuleInterop": true ,
"declaration": true,
"noImplicitAny": true,
"module": "ES2022",
"moduleResolution": "Node",
"forceConsistentCasingInFileNames": true,
"strict": true ,
"skipLibCheck": true,
"strictNullChecks": true,
},
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
}
}
package.json
"name": "@repo/db",
"version": "0.0.0",
"private": true,
"main": "src/index.ts",
"type": "module",
"scripts": {
"generate": "drizzle-kit generate:pg",
"push": "node -r esbuild-register src/migrate.ts",
"migrate": "node -r esbuild-register src/migrate.ts",
"studio": "drizzle-kit studio"
},
"dependencies": {
"@auth/core": "^0.27.0",
"@neondatabase/serverless": "^0.8.1",
"@next/env": "^14.1.0",
"adaptrs": "link:@auth/core/adaptrs",
"dotenv": "^16.4.1",
"drizzle-orm": "^0.29.3",
"esbuild-register": "^3.5.0",
"pg": "^8.11.3",
"server-only": "^0.0.1",
"zod": "^3.22.4"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/node": "^20.11.17",
"@types/pg": "^8.10.9",
"drizzle-kit": "^0.20.13",
"typescript": "^5.3.3"
}
}
tsconfing.json
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@repo/typescript-config/base.json",
"exclude": ["dist"],
"compilerOptions": {
"outDir": "dist",
"target": "ES2022",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "Node16",
"moduleResolution": "Node16",
"resolveJsonModule": true,
"noUncheckedIndexedAccess": true,
"allowSyntheticDefaultImports": true,
},
"include": ["src", "*.ts", "env.mjs", "**/*.ts"],
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
}
}
I tried to switch back to commonjs but failed. I tried to find similar question but was not able to find. I am new to development and this my first time working with Turborepo and Drizzle. Thank you in advance.
Upvotes: 0
Views: 501