Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Entity
✓ import { Entity } from '@mikro-orm/core'
✗ const { Entity } = require('mikro-orm')
ESM-only since v6; CommonJS require produces error. Use named imports from @mikro-orm/core.
PrimaryKey
✓ import { PrimaryKey } from '@mikro-orm/core'
✗ import { PrimaryKey } from 'mikro-orm'
Import from package name 'mikro-orm' is deprecated; use @mikro-orm/core.
MikroORM
✓ import { MikroORM } from '@mikro-orm/core'
✗ import MikroORM from '@mikro-orm/core'
Default export does not exist; must use named import.
defineConfig
✓ import { defineConfig } from '@mikro-orm/core'
Utility for type-safe configuration object.
EntityManager
✓ import { EntityManager } from '@mikro-orm/core'
✗ import { EntityManager } from 'mikro-orm'
Always import from @mikro-orm/core.
Creates an entity, persists it to an in-memory SQLite database, and retrieves it using the EntityManager.
import { Entity, PrimaryKey, Property, MikroORM, defineConfig } from '@mikro-orm/core';
import { SqliteDriver } from '@mikro-orm/sqlite';
@Entity()
class User {
@PrimaryKey()
id!: number;
@Property()
name!: string;
}
const orm = await MikroORM.init({
entities: [User],
dbName: ':memory:',
driver: SqliteDriver,
});
const em = orm.em;
const newUser = em.create(User, { name: 'Alice' });
await em.persistAndFlush(newUser);
const user = await em.findOneOrFail(User, { name: 'Alice' });
console.log(user);
await orm.close();
Errors
Common errors & fixes
TypeError: Cannot use import statement outside a module
Running ESM code in a CommonJS project without proper configuration.
fixAdd "type": "module" to package.json or rename file to .mjs.
Error: No metadata for entity User. Ensure that the entities are correctly registered or that the compiler is configured.
Entities not registered in MikroORM.init() or metadata not generated.
fixAdd entities to config: `entities: [User]` or enable `entityGenerator` metadata discovery.
Cannot find module '@mikro-orm/sqlite' or its corresponding type declarations.
Driver package not installed.
fixRun `npm install @mikro-orm/sqlite` (or appropriate driver).
Column 'name' does not exist in table 'user'
Database schema not synchronized with entities.
fixEnsure schema is synced: call `await orm.getSchemaGenerator().createSchema()` or use `ensureDatabase()`.
Audit
Dependencies
@mikro-orm/corerequiredCore library required for all drivers
@mikro-orm/sqliteoptionalSQLite driver (optional if using other databases)
@mikro-orm/postgresqloptionalPostgreSQL driver (optional if using other databases)
@mikro-orm/mysqloptionalMySQL driver (optional if using other databases)
@mikro-orm/mongodboptionalMongoDB driver (optional if using other databases)