{"id":14524,"library":"db-migrate-plugin-typescript","title":"DB Migrate TypeScript Plugin","description":"This package provides a plugin for `db-migrate` that enables the use of TypeScript for database migration files. It automatically transpiles `.ts` files found in the migration directory using your project's `tsconfig.json`. The current stable version is 2.0.0, released in December 2017. As a plugin, its release cadence is tied to the `db-migrate` ecosystem, but its own updates have been infrequent. Key differentiators include seamless integration with `db-migrate` for TypeScript-based migrations, leveraging existing `tsconfig.json` configurations, and simplifying database schema management for TypeScript projects without requiring manual transpilation steps. It requires `ts-node` as a peer dependency for runtime TypeScript compilation.","status":"maintenance","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/db-migrate/plugin-typescript","tags":["javascript","dbmigrate","db-migrate","db","migrate","migration","migrator","database","sql"],"install":[{"cmd":"npm install db-migrate-plugin-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add db-migrate-plugin-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add db-migrate-plugin-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for runtime TypeScript compilation of migration files by db-migrate.","package":"ts-node","optional":false}],"imports":[{"note":"This package is a db-migrate plugin and is not directly imported into user code. It is loaded by db-migrate automatically once installed. Its primary interaction is via the file system for migration files and its configuration via tsconfig.json.","symbol":"db-migrate-plugin-typescript","correct":"npm install db-migrate-plugin-typescript ts-node"},{"note":"While this plugin enables TypeScript, the core Migration interface comes from `db-migrate` itself (or its associated types). Ensure `@types/db-migrate` is installed if you want type checking within your migration files.","symbol":"Migration interface","correct":"import { Migration } from 'db-migrate';"}],"quickstart":{"code":"{\n  \"compilerOptions\": {\n    \"target\": \"ESNext\",\n    \"module\": \"CommonJS\",\n    \"esModuleInterop\": true,\n    \"strict\": true,\n    \"outDir\": \"./dist\",\n    \"rootDir\": \"./migrations\"\n  },\n  \"include\": [\"./migrations/**/*.ts\"]\n}\n\n// migrations/1678886400000_create_users_table.ts\nimport { Migration } from 'db-migrate';\n\nexport const up: Migration = async (db) => {\n  await db.createTable('users', {\n    id: { type: 'int', primaryKey: true, autoIncrement: true },\n    name: { type: 'string', length: 50, notNull: true },\n    email: { type: 'string', length: 100, notNull: true, unique: true },\n    created_at: { type: 'timestamp', notNull: true, defaultValue: new Date() }\n  });\n};\n\nexport const down: Migration = async (db) => {\n  await db.dropTable('users');\n};\n\n// To install: npm install db-migrate db-migrate-plugin-typescript ts-node @types/db-migrate --save-dev\n// To run: db-migrate up","lang":"typescript","description":"This quickstart demonstrates how to configure `tsconfig.json` for TypeScript migrations and provides an example of a `.ts` migration file. It also shows the npm commands to install the plugin and `ts-node`."},"warnings":[{"fix":"Explicitly install `ts-node` as a direct or dev dependency: `npm install ts-node` or `yarn add ts-node`.","message":"In version 2.0.0, `ts-node` was changed from a direct dependency to a peer dependency. If you upgrade to v2.0.0 or later, `ts-node` must be explicitly installed in your project.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"After running `db-migrate create MyMigration`, manually rename the generated JavaScript file (e.g., `MyMigration.js`) to a TypeScript file (e.g., `MyMigration.ts`) and convert its contents to TypeScript.","message":"The `db-migrate create <name>` command does not generate TypeScript files. It will create a `.js` file, even with this plugin installed.","severity":"gotcha","affected_versions":"*"},{"fix":"Test thoroughly with your current environment (Node.js, TypeScript, `db-migrate` versions). Be prepared for potential compatibility problems and consider contributing to the project or seeking alternatives if persistent issues arise.","message":"The last release (v2.0.0) was in December 2017. This may lead to compatibility issues with newer Node.js, TypeScript versions, or recent `db-migrate` updates.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install `ts-node` explicitly: `npm install ts-node` or `yarn add ts-node`.","cause":"The `ts-node` package, a peer dependency, is not installed in the project.","error":"Error: Cannot find module 'ts-node' from '<path>'"},{"fix":"Ensure `db-migrate-plugin-typescript` is installed and listed in your `package.json`. Verify that your migration files are named with a `.ts` extension (e.g., `123456789_create_table.ts`).","cause":"The plugin might not be correctly recognized by `db-migrate`, or the migration file does not end with the expected `.ts` extension.","error":"Migration file '<filename>' not found or could not be loaded"},{"fix":"Verify that `ts-node` is installed and that your `tsconfig.json` is correctly set up. Ensure `compilerOptions.module` is set to `\"CommonJS\"` (or compatible) if you are running Node.js in a CJS context, and `compilerOptions.esModuleInterop` is `true`.","cause":"`ts-node` or your `tsconfig.json` is misconfigured, preventing proper transpilation of ES module syntax to CommonJS (which Node.js typically expects outside of explicit ESM projects).","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}