Open STNeto1 opened 1 year ago
I also get SyntaxError: Cannot use import statement outside a module
from the first import of helper package when I run drizzle-kit generate:pg
. I'm using esm in package.
@karmux @STNeto1 do you have anything else in file with schemas except of tables/enums?
Ideally is to have schema.ts
(Or any name you want to use for this file) containing only database schema definitions
The current files, @AndriiSherman
// DB
import { connect } from "@planetscale/database";
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { env } from "~/env.mjs";
const connection = connect({
host: env.DATABASE_HOST,
username: env.DATABASE_USERNAME,
password: env.DATABASE_PASSWORD,
});
export const db = drizzle(connection, {
logger: true,
});
// =============
// SCHEMA
import {
serial,
text,
timestamp,
varchar,
} from "drizzle-orm/mysql-core/columns";
import { mysqlTable } from "drizzle-orm/mysql-core/table";
export const shortLink = mysqlTable("short_links", {
id: serial("id").primaryKey(),
url: text("url").notNull(),
slug: varchar("slug", {
length: 20,
}).notNull(),
created_at: timestamp("created_at").notNull().defaultNow(),
});
I can't see anything else being imported that would cause the issue
I'm importing own esm package to schemas that contains some convenience helper functions.
Minimum reproducible example:
Download and extract example utils package drizzle-utils.tar.gz
Run npm install
and npm run build
inside drizzle-utils
Add it as a local dependency of an app that has migrations and run npm install
"drizzle-utils": "../drizzle-utils",
Add these two lines to the header of schemas.ts
import { createTimestampColumns } from 'drizzle-utils';
console.log(createTimestampColumns());
This triggers SyntaxError: Cannot use import statement outside a module
error when trying to generate migration.
Did you get this working?
No. @AndriiSherman in Discord said that he reproduced it and started working on it.
would like support for t3-env
or some other way to read environment variables?
see https://github.com/t3-oss/t3-env/issues/180 for more.
in my next.js app, everything works but i wish drizzle-kit
has some built-in support for it because those are the only commands that fail to read .env
file or check validations. i wish it somehow works magically.
When using
npx drizzle-kit generate:mysql
with other source for env variables, an error is thrown.The .env validation comes from here
The issue on code can be found here