Registry / database / mikro-orm

mikro-orm

JSON →
library7.1.3jsnpmunverified

TypeScript ORM for Node.js based on Data Mapper, Unit of Work, and Identity Map patterns. Current stable version is 7.1.3, with monthly releases. Supports MongoDB, MySQL, PostgreSQL, SQLite, and MariaDB. Key differentiators include automatic schema synchronization, support for complex entity relationships, and first-class TypeScript support with strict type safety.

npm install mikro-orm
INSTALL
IMPORT
SIG · MIKRO-ORM
M
mikro-orm
databasejavascriptv7.1.3
harness data pending
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();
Debug
Known issues
breakingSince version 6, MikroORM is ESM-only. CommonJS require and dynamic imports with CJS context will fail.
fix
Set "type": "module" in package.json or use .mjs extension. Alternatively, upgrade to v7 which remains ESM-only.
affects: >=6.0.0
breakingDefault export removed in v6: import { MikroORM } from '@mikro-orm/core' instead of default import.
fix
Replace default import with named import: import { MikroORM } from '@mikro-orm/core'
affects: >=6.0.0
deprecatedImporting from 'mikro-orm' package is deprecated since v6. Use @mikro-orm/core and specific driver packages.
fix
Install @mikro-orm/core and any drivers (e.g., @mikro-orm/sqlite) and import from them.
affects: >=6.0.0
gotchaEntity decorators (e.g., @Entity()) must be called with parentheses even if no arguments.
fix
Always use @Entity() not @Entity
affects: >=5.0.0
breakingIn v5, the em.persist() method no longer auto-flushes; you must call em.flush() or em.persistAndFlush().
fix
Use em.persistAndFlush() or chain em.persist(entity); await em.flush();
affects: >=5.0.0 <6.0.0
Errors
Common errors & fixes
TypeError: Cannot use import statement outside a module
Running ESM code in a CommonJS project without proper configuration.
fix
Add "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.
fix
Add 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.
fix
Run `npm install @mikro-orm/sqlite` (or appropriate driver).
Column 'name' does not exist in table 'user'
Database schema not synchronized with entities.
fix
Ensure schema is synced: call `await orm.getSchemaGenerator().createSchema()` or use `ensureDatabase()`.
Upgrade
Version history
7.1.3latest on npm
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)
Agent activity
3 hits · last 30 days
node
2
Resources
mikro-orm — npm install mikro-orm · libregistry