Johanne
Johanne
DTDrizzle Team
Created by Johanne on 3/4/2024 in #help
How can I get imports with file extensions?
I have an azure function that runs on node, and use Drizzle for a postgres database. The node/typescript setup we have require explicit file endings, and I have not been able to find any way of turning it off. How can I configure drizzle-orm to use the same import setup as the rest of our application? We use drizzle-orm and drizzle-kit. Our current setup is: tsconfig.json:
{
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "Node",
"outDir": "dist",
"rootDir": ".",
"sourceMap": true,
"strict": false,
"esModuleInterop": true,
"skipLibCheck": true,
"strictNullChecks": true
}
}
{
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "Node",
"outDir": "dist",
"rootDir": ".",
"sourceMap": true,
"strict": false,
"esModuleInterop": true,
"skipLibCheck": true,
"strictNullChecks": true
}
}
drizzle.config.ts:
export default defineConfig({
schema: "./src/database/schema/*",
out: "./migrations",
driver: "pg",
dbCredentials: {
...
},
verbose: true,
strict: true,
}) satisfies Config;
export default defineConfig({
schema: "./src/database/schema/*",
out: "./migrations",
driver: "pg",
dbCredentials: {
...
},
verbose: true,
strict: true,
}) satisfies Config;
package.json:
{
"name": "buildings",
"version": "1.0.0",
"type": "module",
"main": "dist/src/functions/*.js",
...
}
{
"name": "buildings",
"version": "1.0.0",
"type": "module",
"main": "dist/src/functions/*.js",
...
}
This is an example of a schema with an import that fails when we run drizzle-kit generate:pg:
import { uuid, text, timestamp, pgTable } from "drizzle-orm/pg-core";
import { zones } from "./zones.js";

export const devices = pgTable("devices", {
id: uuid("id").unique().notNull().defaultRandom(),
zoneId: uuid("zoneId").references(() => zones.id, {
onDelete: "cascade",
}),
});
import { uuid, text, timestamp, pgTable } from "drizzle-orm/pg-core";
import { zones } from "./zones.js";

export const devices = pgTable("devices", {
id: uuid("id").unique().notNull().defaultRandom(),
zoneId: uuid("zoneId").references(() => zones.id, {
onDelete: "cascade",
}),
});
The error we get is:
Reading config file '.../drizzle.config.ts'
Error: Cannot find module './zones.js'
Reading config file '.../drizzle.config.ts'
Error: Cannot find module './zones.js'
If I remove .js from the import, the migration runs, but our azure function does not. Can anyone help me set it up with consistent imports? It does not matter to me if its with or without extensions, I just need node and drizzle to use the same.
1 replies