Closed exp131 closed 1 year ago
import dataSource from './orm/datasource.js';
import { User } from './orm/models/user.js';
dotenv.config();
Can you check if you have access to environment variables in your datasource/User files? dotenv
should rather be at the top of the file. I prefer to use a CLI version myself:
"start": "dotenv -c '.env' -- node dist/server/index.js",
Yes, it is available. I even disabled dotenv completely in the project, but the error remains the same.
To update: Here data source and entity configs used:
orm/datasource.ts
import { DataSource } from 'typeorm';
const SqliteDataSource = new DataSource({
type: 'sqlite',
database: './db.sqlite'
});
export default SqliteDataSource;
orm/models/user.ts
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity({ name: 'User' })
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
public id: number;
@Column()
public firstName: string;
@Column()
public lastName: string;
}
Is there a specific reason why you don't add your User entity to your datasource? In comparison, this is my config for Postgres:
import { DataSourceOptions } from 'typeorm';
import '../config/index.js'; // dotenv
import Admin from '../modules/admins/entities/admin.entity.js';
import Customer from '../modules/customers/entities/customer.entity.js';
import Category from '../modules/categories/entities/category.entity.js';
import Product from '../modules/products/entities/product.entity.js';
import Order from '../modules/orders/entities/order.entity.js';
import OrderItem from '../modules/orders/entities/order-item.entity.js';
import Dataset from '../modules/datasets/entities/dataset.entity.js';
import { CreateDatabaseStructure1693219188675 } from './migrations/1693219188675-CreateDatabaseStructure.js';
const config: DataSourceOptions = {
type: 'postgres' as const,
url: process.env.DATABASE_URL ?? process.env.POSTGRES_DATABASE_URL,
synchronize: process.env.DATABASE_SYNC === 'true',
logging: process.env.DATABASE_LOGGING === 'true',
entities: [Admin, Customer, Category, Product, Order, OrderItem, Dataset],
migrations: [CreateDatabaseStructure1693219188675],
migrationsRun: false,
migrationsTableName: 'migrations',
migrationsTransactionMode: 'all',
subscribers: [],
extra: process.env.REQUIRE_SSL === 'true'
? { ssl: { require: true, rejectUnauthorized: false } }
: undefined,
};
I just followed the docs, but this is a solution. Now it working fine, thanks a lot @dziraf
Issue fixeed
And the error:
Originally posted by @exp131 in https://github.com/SoftwareBrothers/adminjs/issues/976#issuecomment-1705411603